English 中文(简体)
1. 实体框架4.1 Linq 内容和开端 页: 1
原标题:Entity Framework 4.1 Linq Contains and StartsWith

我首先使用实体框架法。 我想从数据库中询问有关清单物体的内容。 这本书用的是包裹,但我如何将其与起始点结合?

这是我的法典:

List<string> values = new List<string>();
values.Add("A");
values.Add("B");
context.Customer.Where(c => values.Contains(c.Name)).ToList();

How can i query against all customers which starts with A or B?

最佳回答

这应当记忆犹新,但我不敢肯定,这是否能够通过欧洲教育论坛转化为:

context.Customer.Where(c => values.Any(s => c.Name.StartsWith(s))).ToList();
问题回答

你不需要将它与起始点结合起来,因为如果它从A或B开始,它显然包含A或B。 它从A或B开始,不包含A或B。

因此,只是使用先令,而不是征服。

context.Customer.Where(c => c.StartsWith("A") || c.StartsWith("B")).ToList(); 

您可以尝试将这两项职能结合起来:

IQueryable<Customer> result = (from C in context.Customerwhere C.Name.StartsWith("B") && values.Contains(C.Name));




相关问题
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. ...

热门标签