LINQ to SQL - 拆分并重新加入全名 [英] LINQ to SQL - Split and re-join full name

查看:52
本文介绍了LINQ to SQL - 拆分并重新加入全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我试图从Users表中提取记录并将它们推送到gridview中。用户的名称在一列中:FullName。问题是我需要按姓氏订购gridview。

我想我要做的是拆分FullName并重新加入。我已经尝试了LET关键字,但是我收到了一个ArrayIndex错误。



这是我试图拆分的样本:

George Washington> >将是>>华盛顿,乔治

Francis Scott Key>>将是>> Scott Key,Francis



这是关于我得到的,它不起作用...


Hello,
I am trying to pull records from a Users table and push them into a gridview.  The User's names are in one column: FullName.  The problem is that I need to order the gridview by last name.
What I think I want to do is split the FullName and rejoin.  I have tried the LET keyword, but am getting an ArrayIndex error.

Here's a sample of what I am trying to split:
George Washington >> will be >> Washington, George
Francis Scott Key >> will be >> Scott Key, Francis

Here's about as far as I got and it doesn't work...




























var qry = from u in 用户
let arr = u.FullName。拆分('')。ToArray()
选择
{
UserId = u.UserId,
FullName = arr [1] + " ;," + arr [0]
};
            var qry = from u in Users 
                      let arr = u.FullName.Split(' ').ToArray() 
                      select new 
                      { 
                          UserId = u.UserId, 
                          FullName = arr[1] + ", " + arr[0] 
                      }; 

推荐答案

这里的问题是你将如何知道哪些部分是姓和哪个姓。例如在你的第二个例子中,你怎么知道斯科特是他的姓,而不是他的名字或中间名的一部分?
The problem here is how you will know which parts are the forename and which the surname. e.g. in your second example how do you know that Scott is his surname and not part of his forename or a middle name?


这篇关于LINQ to SQL - 拆分并重新加入全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆