将列表linq表达式转换为Defined list Class [英] Convert a list linq expression to Defined list Class
本文介绍了将列表linq表达式转换为Defined list Class的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你有这堂课
Private Class MyClass
Public Property propertyOne() as String
Public Property propertyTwo() as String
Public Property propertyN() as Integer
End Class
现在我想从lambda或linq表达式中填充MyClass的列表,像这样....
Now i want fill a list of MyClass from lambda or linq expression, some like this....
Dim myClassList as new List(Of MyClass)
myClassList = (From lOtherList1 in MyOtherList1.GetAll()
join lOtherList2 in MyOterhList2.GetAll() on lOtherList1.Id Equals lOtherList2.Id
Select myClassList.Add(new MyClass With { .propertyOne = lOtherList1.Field1,
.propertyTwo = lOtherList1.Field2,
.propertyN = lOtherList2.Field1 })).Tolist()
但是我得到这个错误表达式不产生值",我该怎么做?
but i get this error "Expression does not produce a value", how i make this ?
推荐答案
myClassList.Add
是您的查询中的错误部分,请按如下所示进行
myClassList.Add
is wrong part in your query, edit it as follow:
Dim myClassList as new List(Of MyClass)
myClassList = (From lOtherList1 in MyOtherList1.GetAll()
join lOtherList2 in MyOterhList2.GetAll()
on lOtherList1.Id Equals lOtherList2.Id
Select new MyClass With
{
.propertyOne = lOtherList1.Field1,
.propertyTwo = lOtherList1.Field2,
.propertyN = lOtherList2.Field1
})).Tolist()
这篇关于将列表linq表达式转换为Defined list Class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文