Asp.net 强制实体框架不使用NCLOB数据类型
所以我使用ASP.NET Identity+Entity Framework,每当我从代码生成数据库时,许多列类型都是非常重的NCLOB 现在有几种方法可以修改列的类型,例如Asp.net 强制实体框架不使用NCLOB数据类型,asp.net,asp.net-mvc,entity-framework,oracle11g,asp.net-identity,Asp.net,Asp.net Mvc,Entity Framework,Oracle11g,Asp.net Identity,所以我使用ASP.NET Identity+Entity Framework,每当我从代码生成数据库时,许多列类型都是非常重的NCLOB 现在有几种方法可以修改列的类型,例如HasColumnType方法,或者通过设置StringLength属性,或者通过配置modelbuilder为那些还没有属性的人提供HasMaxLength属性 identity的问题是一些专门用于id的列设置得比较晚 因此,在迁移文件中,我有以下内容: UserId = c.Str
HasColumnType
方法,或者通过设置StringLength属性,或者通过配置modelbuilder为那些还没有属性的人提供HasMaxLength
属性
identity的问题是一些专门用于id的列设置得比较晚
因此,在迁移文件中,我有以下内容:
UserId = c.String(nullable: false, maxLength: 128),
Email = c.String(maxLength: 256),
EmailConfirmed = c.Decimal(nullable: false, precision: 1, scale: 0),
PasswordHash = c.String(),
SecurityStamp = c.String(),
PhoneNumber = c.String(),
现在,在应用我在网上找到的代码之后:
modelBuilder.Properties()
.Where(p => p.PropertyType == typeof(string) &&
p.GetCustomAttributes(typeof(MaxLengthAttribute), false).Length == 0 )
.Configure(p => p.HasMaxLength(2000));
迁移代码如下所示:
UserId = c.String(nullable: false, maxLength: 2000),
Email = c.String(maxLength: 256),
EmailConfirmed = c.Decimal(nullable: false, precision: 1, scale: 0),
PasswordHash = c.String(maxLength: 2000),
SecurityStamp = c.String(maxLength: 2000),
PhoneNumber = c.String(maxLength: 2000),
如果您注意到,UserID
已经被设置为某个值,但即使如此,它还是改变了
是否有一个不改变的变通方法
谢谢 嗯,我现在只能手动设置它们的属性,希望能找到一个更自动化的解决方案
modelBuilder.Entity().ToTable(“Users”).Property(p=>p.Id).HasColumnName(“UserId”).HasMaxLength(128);
modelBuilder.Entity().ToTable(“Users”).Property(p=>p.Id).HasColumnName(“UserId”).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserRoles”).Property(p=>p.RoleId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserRoles”).Property(p=>p.UserId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserLogins”).Property(p=>p.UserId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserLogins”).Property(p=>p.ProviderKey).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserLogins”).Property(p=>p.LoginProvider).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserClaims”).Property(p=>p.UserId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“Roles”).Property(p=>p.Id).HasMaxLength(128);
好吧,我现在只能手动设置它们的属性,希望找到一个更自动化的解决方案
modelBuilder.Entity().ToTable(“Users”).Property(p=>p.Id).HasColumnName(“UserId”).HasMaxLength(128);
modelBuilder.Entity().ToTable(“Users”).Property(p=>p.Id).HasColumnName(“UserId”).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserRoles”).Property(p=>p.RoleId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserRoles”).Property(p=>p.UserId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserLogins”).Property(p=>p.UserId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserLogins”).Property(p=>p.ProviderKey).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserLogins”).Property(p=>p.LoginProvider).HasMaxLength(128);
modelBuilder.Entity().ToTable(“UserClaims”).Property(p=>p.UserId).HasMaxLength(128);
modelBuilder.Entity().ToTable(“Roles”).Property(p=>p.Id).HasMaxLength(128);