linq查询的别名列名 [英] Alias column names for a linq query

查看:87
本文介绍了linq查询的别名列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在写一个linq qyery来获取输出,但我想要列的一些别名。我的查询是这样的





Hi,

I am writing a linq qyery to get the output, but i want some alias names for the columns. my query is like this


var q = from a in Number
        join b in Dupnum on a.ID equals b.ID
                           select new
                           {
                                a.Number ,
                                a.LineNumber,
                               a.Item,
                               a.Des,
                               a.SerialNumber
                           };





我这样写的别名是



I am writing like this for alias name

["Number#"] = a.Number ,
[Lime Number#] =a.LineNumber



但它给我的错误就像无效的匿名类型成员声明,​​匿名类型必须声明



问候,

S.Inayat


But it was throwing me the error like" Invalid anonymous type member declare, anonymous type must be declare"

Regards,
S.Inayat

推荐答案

您应该能够简单地定义一个没有任何额外字符的别名因为别名的名称符合C#命名规则。例如,尝试以下操作:

You should be able to simply define an alias without any extra characters as long as the names of the aliases conform to C# naming rules. For example, try the following:
var q = from a in Number
        join b in Dupnum on a.ID equals b.ID
                           select new
                           {
                               f1 = a.Number ,
                               f2 = a.LineNumber,
                               f3 = a.Item,
                               f4 = a.Des,
                               f5 = a.SerialNumber
                           };


DGV_customergrid.DataSource = from S in dc.CUSTOMERs
                                              select new
                                              {
                                                 CustomerName = S.CUSTOMERNAME,
                                                  Customer2 = S.CUSTOMER2,
                                                  FathersName = S.SO,
                                                  Address = S.RESIDENCE,
                                                  Village = S.VILLAGE,
                                                  Mandal = S.MANDAL
                                              };


我遇到了同样的问题,并在别名前加了一个点。所以在你的代码案例中它将是

。[Number] = a.Number,

。[Lime Number] = a.LineNumber

I had the same problem and added a dot in-front of the alias. So in your code case it would be

.["Number"] = a.Number ,
.[Lime Number] =a.LineNumber


这篇关于linq查询的别名列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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