0

thanks for taking the time to look over my question.

I am trying to get some data along with the related records from a database using a DbContext. I already have an example of this setup for one of my relationships -

protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<FinancialTransaction>()
                .HasOne<LedgerEntry>(e => e.ledger_entry)
                .WithOne(t => t.financial_transaction)
                .HasForeignKey<LedgerEntry>(e => e.financial_transaction_id);
        }

However, I also have a table which has loose references to other records, using a combination of source_id and source_type columns. Source_id is the primary key of the other record, and source_type is the singular name of the other record type (such as "account", "user" etc.).

Is anyone aware of a way to set this up using EntityFramework, similar to my example above? Any advice is appreciated and if you need any more information, please ask :)

Thanks!

this.girish
  • 1,296
  • 14
  • 17
Rob Jeffrey
  • 124
  • 12
  • Is it a one to one relationship? Can you post the entities with relevant properties? – JMP Feb 23 '20 at 06:57
  • It is a one to one relationship. After tinkering a bit more with this I'm not sure if it is possible as the second table does not have a column containing its Type. Still worth making sure though! Thanks – Rob Jeffrey Feb 24 '20 at 09:10

0 Answers0