entity framework invalid column name
i'm having some more problems with entity framework. one of them was resolved here entity framework multiple tables same name
now when i try to insert into either table bo or table bi i get the following error:
{"Invalid column name 'Bo_obrano'.rnInvalid column name 'Bo_boano'.rnInvalid column name 'Bo_ndos'."}
or
{"Invalid column name 'Bi_bistamp'}
as i reverse engineered the database through the use of power tools i now have my mapping for bo like this:
public boMap()
{
// Primary Key
HasKey(t => new { t.obrano, t.boano, t.ndos });
Property(t => t.obrano)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.boano)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.ndos)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
}
and bi mapping like this:
public BiMap()
{
// Primary Key
HasKey(t => t.bistamp);
....
my context class looks like this:
public class PHCDbContext:DbContext
{
//classes mapeadas via reverse
public DbSet<Bi> DadosLinhasEncomendas { get; set; }
public DbSet<Bo> DadosCabecalhosEncomendas { get; set; }
...
public PHCDbContext(string connection):base(connection)
{
Database.SetInitializer<PHCDbContext>(null);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new BiMap());
modelBuilder.Configurations.Add(new boMap());
....
i exported the mapping as instructed in here: export code first model mapping
what i've found is that those fields do not exist per se. as i opened the edmx file in visual studio i found out that those fields are in the navigational property of the class, in the associations part of the model. they represent the primary keys in the tables, not foreign keys. but they are not mapped to any value in the poco class. much less to any column in the database. so how can i solve this? help would be apreciated thanks in advance
i got it to work by removing the navigational property. as there's no correlation between the tables whatsoever. both of them are isolated so far. thanks for the help once again
您的情况看起来有点不同寻常,但您需要查看数据库并查看列名是什么,然后在上下文中映射它:
protected override void OnModelCreating( DbModelBuilder modelBuilder )
{
modelBuilder.Entity<Bi>( ).ToTable( "dbo.Bi" );
modelBuilder.Entity<Bi>( ).Property( p => p.bistamp).HasColumnName("actualName" );
}
链接地址: http://www.djcxy.com/p/94534.html
上一篇: 实体框架首先不会自动映射代码中的属性
下一篇: 实体框架无效的列名称