Query Projection SDK 1.6 Not working
-
10 января 2012 г. 17:31
I'm trying to use query projection to return a large list of results.
It seems that the query part of it is working okay but the projection into a new type is not working
for example:
var query = from entity in MyDB.CurrentContext.CreateQuery<ContentSummary>("Content")
select new ContentSummary()
{
Name = entity.Name,
Created = entity.Created,
Reference = entity.Reference
};
So the source is projected into the simple ContentSummary entity instead of the Content object. If i do the above the result of the query still thinks it's Content objects. If i remove the ContentSummary from the select new part (so it projects into an anonymous type) then it does work.
So what am i missing? The query part is okay but i must have the projection part wrong but i've basically copied the example on MSDN.
I don't know how the var query knows that it should be dealing with Content objects. The table name is content - is there something going on in the library that is making an assumption about the type to use in the query?
help!
cheers
Paul
Все ответы
-
10 января 2012 г. 19:59
It looks like the code is projecting the results into a new ContentSummary object. If the desire is to have a new Content object created, then shouldn't the select part of the query be changed to "select new Content()"?
You could use Fiddler as well to see the request & response. That would at least show the results coming back (being only those fields that were requested and not the entire table).
-
11 января 2012 г. 4:38
What is the error message you're getting? Are you by any chance running your code against development storage? To the best of my knowledge, query projections are still not supported against development storage.
Hope this helps.
Thanks
Gaurav Mantri
Cerebrata Software
-
11 января 2012 г. 8:57
The code is what i want, ContentSummary, however when it comes time to evaluate the query the exception shows that the query result are Content objects. So the projection part is not working as i expect.
Fiddler shows that the Table Storage part is okay, it is just returning the subset of fields i'm asking for.
For some reason the query is IEnumerable<Content> NOT IEnumberable<ContentSummary> very odd. The original table is called Content so i wonder whether the library is doing something behind my back
thanks
paul -
11 января 2012 г. 8:58
I'm running against live storage and i can see the query results are coming back properly, as mentioned in the above response the error is evaluating the query once it's back.
cheers
paul -
26 февраля 2012 г. 0:07
Hi Paul - First, apologies for the long delay. If you're still looking for answers, hopefully this will help.
The code you shared is correct, I've tried similar and it works. The only way I was able to reproduce the results you saw (incorrect type resolution), was if the entity retrieved was already being tracked by the TableServiceContext. In my case, it was because I created the full entity, added it to the TableServiceContext, and saved changes. After this, using the same ServiceContext, I did the projection query, which hit the same problem you're seeing - the returned entity was of the full entity type, not the projection entity type. If this describes the behavior of your application, I recommend using a new TableServiceContext object or use the TableServiceContext.Detach() method to detach the full entity from the TableServiceContext before making your projection query.
Hope that helps - let me know if it doesn't, and we'll keep looking. Again, sorry for the long delay!
-Jeff

