【发布时间】:2017-02-09 10:25:06
【问题描述】:
我是实体框架(实际版本 6)新手,尝试做一些查询。
我的数据库看起来与此类似:
我尝试了一个查询(不正确),例如:
Dim products = db.Product.Include(Function(p) p.Status).Include(Function(p) p.Status.StatusTranslations).AsExpandable().Where(predicate).Where(Function(p) p.Status.StatusTranslations.Language.Equals("en-Us"))
其中 AsExpandable() 是来自 LinqKit 的函数。
这就是我想要的 SQL:
Select *, st.StatusDescription from Product As p
Join Status As s On p.StatusId = s.Id
Join StatusTranslations As st on s.Id = st.StatusId
Where (...predicate...) And st.Language = 'en-US'
这样我就可以在我的视图中显示 StatusDescription:
@ModelType IEnumerable(Of Product)
...
@For Each item In Model
@Html.DisplayFor(Function(modelItem) item.Status.StatusTranslations.StatusDescription)
Next
在我看来,我收到了错误:
StatusDescription 不是 ICollection 的成员(的 状态翻译)
问题是,vb.net 查询应该如何实现这一点?是否需要更改数据库架构和/或视图?
【问题讨论】:
标签: .net asp.net-mvc vb.net entity-framework