Multi-Tenant With Code First EF6

后端 未结 4 1894
小鲜肉
小鲜肉 2020-11-27 13:55

Our organization has need to have a single database, multi-tenant
(by table schema, not by tenant id) architecture.

There is a great article h

4条回答
  •  悲哀的现实
    2020-11-27 14:24

    very nice approach and it helped me to get a more straight forward solution. You may override only the Name-Method, it is used in every writer .... Sorry for new answer, but i'm not allowed to comment ....

    public class SqlServerSchemaAwareMigrationSqlGenerator:SqlServerMigrationSqlGenerator
    {
    
        private string _schema;
    
        public accountMigrationSqlGenerator(string schema)
        {
            _schema = schema;
        }
    
        protected override string Name(string name)
        {
    
            int p = name.IndexOf('.');
            if(p>0)
            {
                name = name.Substring(p + 1);
            }
    
            return $"[{_schema}].[{name}]";
    
        }
    
    }
    

提交回复
热议问题