Entity Framework - get related items without explicit reference using Fluent API configurations

api c# entity-framework-6 fluent

Question

If I have database table A with optional attribute X, for example. Table B in my database has a composite key (Y, X). There is no clear relationship between these two tables.

e.g.

create table A
(
    Id uniqueidentifier not null,
    X uniqueidentifier null
)

create table B
(
    Y uniqueidentifier not null,
    X uniqueidentifier not null,
    Constraint PK_B Primary Key (Y, X)
)

Due to the fact that X is an orphan id, A and B are implicitly connected (its base table has been moved out)

How can I fill my model A in C# code?IList<B> obtaining all of the objects in B that possess property X using X? I'd like to use Fluent API setups.

e.g

public class A {
    public Guid Id {get; set;}
    public Guid? X {get; set;}
    public IList<B> RelatedItems {get; set;}
}

public class B {
    public Guid X {get; set;}
    public Guid Y {get; set;}
}

How can I set up my entities in Fluent API to utilise something like

var list = await context.AQuery()
.Include(a => a.RelatedItems)
.ToListAsync().ConfigureAwait(false);

or another method to fill IList in A

I appreciate it.

1
1
8/19/2018 8:24:08 PM

Popular Answer

ZZZ_tmp
0
8/19/2018 4:46:42 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow