OData Linq problem
I've created an application that exposes a self-hosted OData web service. The web service exposes a collection of objects named "Main". Each of these Main objects has a reference to a releated "Details" object, which is very large (many properties, nearly a hundred).
I now use LinqPad to test my web service, which seems to work fine.
Often I need information from both the "Main"-collection and the related "Details" object. This can be accomplished by running the following linq query:
from m in Main.Expand( "Details" )
where m.ID==57
select m
This correspons to the url:
"http://MachineName:port/ServiceName/Main()?$filter=ID eq 57&$expand=Details"
This query works fine and returns the full Main object and the full related Details object.
However, the Details object is very large, and often I only need the value of a single single property from both of the objects.
Manually, I can construct a url that gives me exacly that:
"http://MachineName/ServiceName/Main()?filter=ID eq 57&$expand=Details&$select=Property1,Details/Property2"
which returns xml containing only the value of Main.Property1 and the value of the related Details.Property2.
Question: Why can't I create a linq query that does just that?
Whe开发者_如何学Gon I try something like:
from m in Main.Expand( "Details" )
where m.ID == 57
select new{ m.Property1, m.Details.Property2 }
it gives me the an error message: "NotSupportedException: Cannot create projection while there is an explicit expansion specified on the same query."
I have now given up using Linq to construct the query. But knowing the corrct url like above, how can i use that url directly in code (C# client) and how do I then access the result?
Doesn't just
from m in Main
where m.ID == 57
select new { m.Property1, m.Details.Property2 }
work for you?
精彩评论