English 中文(简体)
使用 linq 的首名
原标题:search firstname from combination of lastname+", "+firstname using linq

我写了一个存储程序, 以以下格式将我回回回客户名 。

LastName+", "+FirstName

我把它分配到下面的属性类别。

Customer = DbContext.ExecuteStoreQuery<SearchEmployeeCDTO>("exec GetCustomerDetails").AsQueryable().ToList();

我现在要搜索最后一个名字, 如下面的我为客户公司所做的Name

if(CompanyName!=null && LastName==null)
Customer = Customer.Where(c => c.CompName.Contains(CompanyName)).ToList();

请建议我如何从最后Name 和 FirstName 格式的组合中查找最后一个Name 。

谢谢,

最佳回答

也许这个?

if(LastName!=null)
  Customer = Customer.Where(c => c.CustName.StartsWith(LastName)).ToList();
问题回答

如果您试图检查另一个列表中包含相同或不相同的值, 您可以使用此值 : (如果您作为通用列表元素的不同属性检索这些值) 。

bool b = your1stList.Exists(c=> c.firstName == your2ndList.firstName ,
                               c.middleName == your2ndList.middleName ,
                               c.lastName  == your2ndList.lastName)

if ( b == true) 
{ 
  MessageBox.Show("You already have this Customer"); 
}

这是收回所有属性的好方法, 无需任何腐蚀活动 。 保护您避免在发酵询问中出现头痛 ;)

在另一方面,如果我们继续从您的查询中进行, 那么您就需要将上名 + 第一名的值移到字符串中, 并使用字符串. Split (”) 函数将它放入字符串数组中, 如果最后一个单词Name+第一名检查了最后一个名的数组 [0] 索引和第一个名的数组 [1] 。

你想选哪条路...





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

热门标签