N
N
Nik Faraday2022-04-15 23:20:00
C++ / C#
Nik Faraday, 2022-04-15 23:20:00

Why doesn't Entity Framework Core create columns in a table?

Hello!

The problem is as follows:
I have three entities: Bank Account, Client and Bank Card. (Bank -> Client one to one, Client -> Card one to many). I blinded it, it seems to be a working data scheme in the context, gave the migration, the migration passed, did the database update, also successfully. But! But in the database itself, the entity, for example, cards, has a link to the user, just like the Bank has a link to the user, despite the fact that the user does not have COLUMNS in the table at all, for links to other entities, such as bank and cards. I did a drop database several times and recreated it, nothing helps, a new database is created the same. Below I threw the last two options for setting up a data schema in the context

modelBuilder.Entity<ClientEntity>()
                .HasOne<BankAccountEntity>(client => client.Account)
                .WithOne(account => account.Client)
                .HasForeignKey<BankAccountEntity>(bank => bank.ClientFK);

modelBuilder.Entity<BankAccountEntity>()
                .HasOne<ClientEntity>(account => account.Client)
                .WithOne(client => client.Account)
                .HasForeignKey<BankAccountEntity>(account => account.ClientFK);

modelBuilder.Entity<ClientEntity>()
                .HasMany<CardEntity>(client => client.Cards)
                .WithOne(cards => cards.Client)
                .HasForeignKey(cards => cards.ClientFK);

modelBuilder.Entity<CardEntity>()
                .HasOne<ClientEntity>(cards => cards.Client)
                .WithMany(client => client.Cards)
                .HasForeignKey(cards => cards.ClientFK);


modelBuilder.Entity<ClientEntity>()
                .HasOne<BankAccountEntity>(client => client.Account)
                .WithOne(account => account.Client)
                .HasForeignKey<BankAccountEntity>(bank => bank.ClientFK);

modelBuilder.Entity<ClientEntity>()
                .HasMany<CardEntity>(client => client.Cards)
                .WithOne(cards => cards.Client)
                .HasForeignKey(cards => cards.ClientFK);

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