这确实使我发疯。如下面的图片所示,我创建了一个表格:
这是User实体的流畅配置:
//this is the User entity model class
public class User
{
public long Id { get; set; }
public string EmailAddress { get; set; }
public string HashedPassword { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int IsAdmin { get; set; }
}
public class UserEntityModelBuilder : IEntityModelBuilder
{
public void Build(DbModelBuilder modelBuilder)
{
var config = modelBuilder.Entity<User>();
config.Property(e => e.Id).HasColumnName("ID");
config.Property(e => e.EmailAddress).HasColumnName("EMAIL");
config.Property(e => e.HashedPassword).HasColumnName("PASSWORD");
config.Property(e => e.FirstName).HasColumnName("NOME");
config.Property(e => e.LastName).HasColumnName("COGNOME");
config.Property(e => e.IsAdmin).HasColumnName("ADMIN");
config.ToTable("UTENTIEROGAZIONE").HasKey(e => e.Id);
}
}
现在,我正在运行一个非常简单的LINQ语句,只是为了测试登录名,它会抛出以下奇怪的异常消息:
事实是我只使用VARCHAR2字段,我不明白到底发生了什么...任何线索?
编辑(添加了DbContext初始化):
public BarcodePrinterDbContext(IConnectionStringProvider connectionStringProvider,
IEnumerable<IEntityModelBuilder> entityModelBuilders)
: base(connectionStringProvider.GetConnectionString())
{
_entityModelBuilders = entityModelBuilders ??
throw new ArgumentNullException(nameof(entityModelBuilders));
Database.SetInitializer(
new NullDatabaseInitializer<BarcodePrinterDbContext>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//setting the schema for Oracle DB
SchemaSetup.SetupSchema(modelBuilder);
//registering all entities fluent configurations on the model builder
foreach (var entityModelBuilder in _entityModelBuilders)
entityModelBuilder.Build(modelBuilder);
/*
* I googled out something on wrong mappings on string types,
* so I tried to set all string fields to a maximum of 2000
* characters, unfortunately with no success.
*/
modelBuilder
.Properties()
.Where(p => p.PropertyType == typeof(string) &&
p.GetCustomAttributes(typeof(MaxLengthAttribute), false).Length == 0)
.Configure(p => p.HasMaxLength(2000));
}
答案 0 :(得分:0)
仅供参考,这全都与目标架构设置有关:我正在向旧的SchemaSetup对象注入不同的架构,而不是“ IMPEGNATIVE”。不幸的是,我能够对它运行查询,因为我对db用户设置了各种特权,因此出现了错误(该其他模式中的表实际上有个NCLOB字段)。
因此,请始终检查您的目标架构!