0

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'.\r\nInvalid column name 'Bo_boano'.\r\nInvalid 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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Your situation looks slightly unusual, but you need to look at your database and see what the column name is, then map it within the context:

protected override void OnModelCreating( DbModelBuilder modelBuilder )
{
    modelBuilder.Entity<Bi>( ).ToTable( "dbo.Bi" );
    modelBuilder.Entity<Bi>( ).Property( p => p.bistamp).HasColumnName("actualName" ); 
}

1 Comment

sorry for the late reply,but for instance on my bimap class doesn't the following lines: ToTable("bi"); Property(t => t.bistamp).HasColumnName("bistamp");handle the injection and database mapping?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.