【发布时间】:2012-11-02 11:47:35
【问题描述】:
我有两个具有多对多关系的类(通过实体框架提供):
Corporation which has the member Tags
Tag which has the member name
EntityDataSource 为我提供了我想在给定标记名中过滤的 ObjectQuery,但我不知道如何。我想获取所有标签名称为“myname”的公司。我不知道怎么做 linq 查询
当我查询实体时,很遗憾没有得到 Objectquery。
protected void EntityDataSource1_QueryCreated(object sender, QueryCreatedEventArgs e)
{
// first try
var corps = e.Query.Cast<Corporation>();
// of course doesn't work, because oyu can't access a member (name) of a collection (Tags)
// i don't know the right linq expression for this
e.Query = from c in corps where c.Tags.Name.Contains("myname") select c;
// second try
var tags = from t in entities.Tags where t.Name.Contains("myname") select t;
var filteredcorporations = from c in tags select c.Corporations;
// does not work because it is not a ObjectQuery<Corporation>
e.query = filteredcorporations;
}
我的实体数据源:
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=eodbEntities" DefaultContainerName="eodbEntities" EnableFlattening="False" EntitySetName="Corporations" OnQueryCreated="EntityDataSource1_QueryCreated">
</asp:EntityDataSource>
【问题讨论】:
-
您能提供更多信息吗?您是否阅读过此主题:stackoverflow.com/questions/5456150/…?
-
我想用代码隐藏做一个更复杂的过滤器。
-
你想静态过滤数据源还是什么?
-
静态过滤是什么意思?我想获取所有标签名称为“myname”的公司。
-
你能用 EntityDataSource 显示你的标记吗?
标签: c# asp.net linq entity-framework