Пример #1
0
        internal static void AddModelDefinition(DbModelBuilder modelBuilder, string tableName = "Messages", string schemaName = "dbo")
        {
            var model = BaseIdModel <long> .GetModelDefinition <Message>(modelBuilder, tableName, schemaName);

            model.Column(x => x.CompanyId, "CompanyId", 1);
            model.StringColumn(x => x.Subject, "Subject", 2);
            model.StringColumn(x => x.Body, "Body", 3, isRequired: false, stringMaxLength: DbConstants.StringLength4096);
            model.Column(x => x.SentByUserId, "SentByUserId", 4);
            model.DateTimeColumn(x => x.SentAt, "SentAt", 5);
            model.Column(x => x.IsRead, "IsRead", 6);
            model.DateTimeColumn(x => x.ReatAt, "ReatAt", 7);
            model.Column(x => x.ReadByUserId, "ReadByUserId", 8);
            model.StringColumn(x => x.Code, "Code", 9);
        }
Пример #2
0
        internal static EntityTypeConfiguration <TEntity> GetModelDefinition <TEntity>(DbModelBuilder modelBuilder,
                                                                                       string tableName, string schemaName = "dbo", bool isNameRequired = true, bool isNameUnique = true)
            where TEntity : BaseIdNameModel <T>
        {
            var model = BaseIdModel <T> .GetModelDefinition <TEntity>(modelBuilder, tableName, schemaName);

            model.StringColumn(x => x.Name, "Name", 1, isNameRequired);

            if (isNameUnique)
            {
                model.Property(x => x.Name).HasUniqueIndex($"IX_{tableName}_Name");
            }

            return(model);
        }