Linq to SQL - 填充 IEnumerable 属性
我试图从表(BidNames)中提取一些记录并将它们传递到视图模型中的视图。我的视图模型仅包含 BidName 记录的集合。
我的视图模型:
public class BidNamesVM
{
public IEnumerable<BidName> BidNames { get; set; }
}
我在填充 BidNames 集合时遇到问题。从 bn 到 BidNames 的转换不起作用。
from bn in BidNames
where bn.CustomerID == 1160 && bn.Customer.Bids.Any(b=>b.Item.AuctionID == 2)
select new BidNamesVM
{
BidNames = bn
}
我需要做什么才能在查询中填充 BidNames?
非常感谢,
BK
I am trying to pull some records from a table (BidNames) and pass them to a view in a view model. My view model consists of nothing more than a collection of BidName records.
My view model:
public class BidNamesVM
{
public IEnumerable<BidName> BidNames { get; set; }
}
I'm having problems populating the BidNames collection. The conversion from bn to BidNames isn't working.
from bn in BidNames
where bn.CustomerID == 1160 && bn.Customer.Bids.Any(b=>b.Item.AuctionID == 2)
select new BidNamesVM
{
BidNames = bn
}
What do I have to do to populate BidNames in my query?
Many thanks,
BK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 LINQ 查询已返回
IEnumerable
,其中bn
表示BidName
的单个实例。试试这个:在您的示例中,您尝试将
BidName
的实例设置为IEnumerable
类型的属性,但由于明显的原因,该方法不起作用。Your LINQ query already returns an
IEnumerable<BidName>
, withbn
representing an individual instance ofBidName
. Try this:In your example, you were trying to set an instance of
BidName
to a property of typeIEnumerable<BidName>
, which won't work for obvious reasons.