B
B
bogdanstefanjuk2017-03-08 18:52:08
MySQL
bogdanstefanjuk, 2017-03-08 18:52:08

How to add fields to a database table that participate in relationships using FluentAPI?

Hello.
There was a problem when working with MySQL + EF6.
There are 2 models:

public class Foo{
     public Guid Id { get;set; }
     public string Name { get; set; }

     public List<Boo> Boos { get; set; }
    }
    
    public class Boo{
     public Guid Id { get;set; }
     public string Name { get; set; }

     public Foo Foo { get; set; }
    }

DbContext:
public class FooConfiguration : EntityTypeConfiguration<Lot>
        {
            public FooConfiguration()
            {
                ToTable("foo_table");
                Property(x => x.Id).HasColumnName("foo_id");
                Property(x => x.Name).HasColumnName("foo_name");          
    
                HasMany(x => x.Boo).WithRequired(x => x.foo);
            }
        }

    public class BooConfiguration : EntityTypeConfiguration<Lot>
        {
            public BooConfiguration()
            {
                ToTable("boo_table");
                Property(x => x.Id).HasColumnName("boo_id");
                Property(x => x.Name).HasColumnName("boo_name");          
            }
        }

The problem is that the output is foo_table, but with only 2 fields (Id and Name), how to make it so that there is a BoosId field?
Did the boo_table table have a FooId field?
Thanks for answers.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question