Let's say I have database table A with optional property X. I have table B with a composite key (Y, X). These two tables are not explicitly related in any way.
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)
)
A and B are implicitly related via property X, in the sense that X is an orphan id (its base table has been moved out)
For my model A in C# code, how can I populate IList<B>
using property X to get all items in B containing X? Ideally, I'd like to use Fluent API configurations.
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 do I configure my entities using Fluent API so that I can use something like
var list = await context.AQuery()
.Include(a => a.RelatedItems)
.ToListAsync().ConfigureAwait(false);
or any other way to populate IList in A
Thanks in advance!
in ur model a x is a property , a property has a getter , u can set the get method of the x property to retrieve the records from the database (similar to the lazy loading design pattern )
public IList<SomeStuff> X {
get { // go get records from database }
}
this will cost u an extra so i am not sure if this is what u want