English 中文(简体)
• 如何进行多种对手的林吉问,并将之纳入欧洲复兴开发银行
原标题:How to perform a many-to-many Linq query with Include in the EF

我不知道如何利用Linq和EF来进行这一询问。

Imagine I有三个表A、B和C。

A and B have a many-to-many relationship. B and C have a 1-to-many relationship.

我想从B处获得记录,包括C,但从A s Id中过滤。 我很容易从B处得到记录:

var result = Context.A.Where(x => x.Id.Equals(aId)).SelectMany(x => x.B);

但是,当我试图将C包括在内时,我不知道如何这样做:

//This doesn t work    
var result = Context.A.Where(x => x.Id.Equals(aId)).SelectMany(x => x.B.Include("C"));

另外,我用无uck(相当于上述)来尝试:

//Not working
var result = (from a in Context.A.Where(x => x.Id.Equals(aId))
              from b in a.B.Include("C")
              select b);

感谢您的帮助。

最佳回答

www.un.org/Depts/DGACM/index_french.htm 推广方法

这是解决办法:

var result = (from b in Context.B.Include("C")
              where b.A.Any(x => x.A.Equals(aId))
              select b);
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签