I have two Classes (given via Entity Framework) which are in a many to many relationship:
Corporation which has the member Tags
Tag which has the member name
The EntityDataSource gives me the ObjectQuery which i want to filter in a given tagname but i don't know how. I want to get all corporations, which have a tag with the name "myname". I don't know how to do the linq query
When i query the entities i unfortunately don't get an 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;
}
My EntityDataSource:
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=eodbEntities" DefaultContainerName="eodbEntities" EnableFlattening="False" EntitySetName="Corporations" OnQueryCreated="EntityDataSource1_QueryCreated">
</asp:EntityDataSource>