I have three tables
start
(Id, acctId, detailId) detail
(Id, name) item
(Id, detailId, desc) start
has a one-to-one relationship with detail
, and detail
has a one-to-many relation with item
.
I am trying to write a lambda or linq query so for a given acctId
, I get name
and desc
. I have tried the following using EF but the result is incorrect:
var te = DbContext.Set<start>().Include("detail")
.Where(a=>a.acctId== id && a.detail.items.Any());
If you have navigation properties, and you only want those specific properties:
var te = DbContext.Set<start>().Where(a => a.acctId == id).Select(s => new
{
name = s.detail.name,
descs = s.detail.items.Select(i => i.desc).ToList()
});
There's a possibility you have more underlying issues as well, though...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.