实体框架包含和导航属性
我使用 Asp.net 和 EF 4。
在我的模型中,我有两个实体:CmsGroupsTypes
,其中有一个名为 CmsContents
到实体 CmsContents
的导航属性。
我将 EntityDataSource 控件与 GridView 一起使用。
我需要返回 CmsGroupsTypes
但使用导航属性和 QueryStringParameter
过滤主题。
使用以下代码,我收到错误:
'ContentId' is not a member of 'Transient.collection[CmsModel.CmsContent(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=CmsConnectionStringEntityDataModel" DefaultContainerName="CmsConnectionStringEntityDataModel"
EnableFlattening="False" EntitySetName="CmsGroupsTypes" Include="it.CmsContents.ContentId"
Where="it.CmsContents.ContentId == ContentId">
<WhereParameters>
<asp:QueryStringParameter Name="ContentId" QueryStringField="ContentId" DbType="Int32" />
</WhereParameters>
</asp:EntityDataSource>
知道我做错了什么吗?
我在 LINQ 中有一个等效版本,它正在工作,但我必须直接在 EntityDataSource 控件上实现。
// Get ContentId from Query String.
int myContentId = Convert.ToInt32(ContentIdFromUrl);
// Find all GroupsType for a specific Content.
var myGroupsTypesList = from g in context.CmsGroupsTypes
where g.CmsContents.Any(x => x.ContentId == myContentId)
select g;
I use Asp.net and EF 4.
In my model I have two Entities: CmsGroupsTypes
wich has a navigational property called CmsContents
to Entity CmsContents
.
I'm using an EntityDataSource
control together with a GridView.
I need return CmsGroupsTypes
but filtering theme using the Navigational Property and QueryStringParameter
.
With the following code I receive an error:
'ContentId' is not a member of 'Transient.collection[CmsModel.CmsContent(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=CmsConnectionStringEntityDataModel" DefaultContainerName="CmsConnectionStringEntityDataModel"
EnableFlattening="False" EntitySetName="CmsGroupsTypes" Include="it.CmsContents.ContentId"
Where="it.CmsContents.ContentId == ContentId">
<WhereParameters>
<asp:QueryStringParameter Name="ContentId" QueryStringField="ContentId" DbType="Int32" />
</WhereParameters>
</asp:EntityDataSource>
Any idea what I'm doing wrong?
I have an equivalent version in LINQ and it is working but I have to implementing directily on the EntityDataSource Control.
// Get ContentId from Query String.
int myContentId = Convert.ToInt32(ContentIdFromUrl);
// Find all GroupsType for a specific Content.
var myGroupsTypesList = from g in context.CmsGroupsTypes
where g.CmsContents.Any(x => x.ContentId == myContentId)
select g;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速猜测:
Include
采用导航属性的名称,因此:不应该是这样吗
?
Quick guess:
Include
takes the name of a navigation property, so instead of:shouldn't it be
?