我有两个具有多对多关系的类(通过实体框架提供):
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>