【发布时间】:2011-09-21 05:00:26
【问题描述】:
不知道如何为这个问题写一个好的标题... :)
我是 Linq 新手,不知道我遇到的这个问题应该使用什么语法
class MainClass()
{
string MainKey {get;set;}
string MainName {get;set;}
List<SmallObject> MainList {get;set}
}
class SmallObject()
{
string SmallKey {get;set}
}
林克:
myTable 包含 4 个字符串字段(Field1、Field2、Field3、Field4)
var mainQuery = (from v from myTable
select v)
var myQuery = (from v in mainQuery
select new MainClass()
{
MainKey = v.Field1,
MainName = v.Field2,
MainList = #whats the correct syntax here?#
})
标有#whats the correct syntax here?#的部分是我的问题。 我想将 v.Field3 和 v.Field4 作为项目添加到 MainClass 中的 MainList-object,但我不知道该怎么做。
如果有人能提供帮助,我很高兴。
【问题讨论】: