【发布时间】:2014-03-28 02:07:10
【问题描述】:
下面的 LINQ to Entities 查询会执行一个子查询,并将其结果投射到MyViewModel。
我希望在SubModel 的Text 属性中使用myText 字符串变量获取所有ProjectedModel 对象。
var items = (from t1 in db.MyTable
select new MyModel
{
Id = t1.MyId,
SomeItems = (from s1 in db.MyOtherTable
where s1.LinkedId == t1.Id
select new SubModel
{
Id = s1.Id,
Text = s1.Text
})
}).ToList();
伪代码如下所示:
string myText = "abc";
items = items where SomeItems.Text contains myText
【问题讨论】:
标签: c# linq linq-to-entities