Open stfnmllr opened 13 years ago
I have tried to do this before, also to support data services and it doesn't work like you need it to.
Can you explain your use case as well as an example code snippet of how you will use this?
Thanks for your answer. I put an example together - will send it to you via mail attachment + a brief explanation how to reproduce the issue. Use case: 1:n association in data services I know that in document databases one would likely prefer to use embedded objects, but data services sticks very much to the relational model and does not support navigation attributes in embedded object collections (data services CTP2 / oData V3: Multi-Valued Data Types)
Yes, the issue you are presenting regarding embedded objects is the problem. When you navigate to an embedded object, how are you going to know which root document it belongs to?
Explanation how to reproduce the issue:- Run solution in debugger- Open Browser (first test with Linq to objects). http://localhost:8000/TestServer/Students. Navigate to http://localhost:8000/TestServer/Students(1)/Courses--> Courses will be shown (fine)- Next try with Linq to MongoDB.http://localhost:8000/TestServer/MongoStudents.Navigate to http://localhost:8000/TestServer/MongoStudents(1)/Courses-->First query: queryobject.Where(element => (element.Id == 1))Second query: queryobject.Where(element => (element.Id == 1)).SelectMany(element => Convert(element.Courses))--> this causes the issue as SelectMany is not implemented in the MongoDb Linq provider{-error: {code: ""-message: {lang: "de-DE"value: "Nicht implementiert"}-innererror: {message: "The method 'SelectMany' is not supported"type: "System.NotSupportedException"stacktrace: " bei FluentMongo.Linq.Translators.QueryBinder.VisitMethodCall(MethodCallExpression m) in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\Translators\QueryBinder.cs:Zeile 194. bei FluentMongo.Linq.Expressions.ExpressionVisitor.Visit(Expression exp) in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\Expressions\ExpressionVisitor.cs:Zeile 62. bei FluentMongo.Linq.Expressions.MongoExpressionVisitor.Visit(Expression exp) in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\Expressions\MongoExpressionVisitor.cs:Zeile 31. bei FluentMongo.Linq.Translators.QueryBinder.Bind(Expression expression) in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\Translators\QueryBinder.cs:Zeile 34. bei FluentMongo.Linq.MongoQueryProvider.Translate(Expression expression) in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\MongoQueryProvider.cs:Zeile 163. bei FluentMongo.Linq.MongoQueryProvider.BuildExecutionPlan(Expression expression) in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\MongoQueryProvider.cs:Zeile 145. bei FluentMongo.Linq.MongoQueryProvider.Execute(Expression expression) in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\MongoQueryProvider.cs:Zeile 98. bei FluentMongo.Linq.MongoQuery`1.System.Collections.IEnumerable.GetEnumerator() in d:\develop\dot.net\MongoDbDataService\craiggwilson-fluent-mongo-d8816ac\src\FluentMongo\Linq\MongoQuery.cs:Zeile 112. bei System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)"}}}Hope that helps:-)-----Ursprüngliche Nachricht-----Von: craiggwilson reply@reply.github.comGesendet: 06.06.2011 13:36:02An: MillerSt@web.deBetreff: Re: [fluent-mongo] SelectMany Support in Linq (Feature Request) (#10)>I have tried to do this before, also to support data services and it doesn't work like you need it to.>>Can you explain your use case as well as an example code snippet of how you will use this?>>-->Reply to this email directly or view it on GitHub:>https://github.com/craiggwilson/fluent-mongo/issues/10#comment_1308633 Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die Toolbar eingebaut! http://produkte.web.de/go/toolbar
Please see the mail and the attached solution for more details. Sorry, maybe I was not clear enough in describing the use case. It is just about a 1:n association between two entities (no embedded objects). I just mentioned embedded components as a more canonical approach in document database modeling, but oData does not support references in the same.
So, I think we are miscommunicating. I know how SelectMany operates. However, in the context of DataServices, it isn't going to help you at all.
Your second query from above shouldn't be written with a Where and a SelectMany. It should be written as:
var courses = queryObject.Single(x => x.ElementId == 1).Courses;
This is how data services should be handling this as well:
/Students(1)/Courses -> get the student with a primary key of 1 and select it's courses.
However, as you stated, data services assumes a relational model and exposing courses like above is not possible due to how data services works (at least in the way I tried to handle this).
Hopefully you are understanding what I'm saying. I'm fine adding support for SelectMany, but I want you to be aware that it is probably not going to solve the problem you are trying to address.
Thank you very much for the analysis and your answer.
I also was wondering about 'data services' using the Where / SelectMany query instead of the way you described it. I checked the 'oData URI conventions' in addition but nothing indicates the usage for 'Where' with regards to accessing resources via key. So, the only reason I can think of is 'supporting' the erroneous case of having duplicate key values. Implementing it via 'Where' will 'find' all duplicates in Students - and 'SelectMany' will list all 'Courses' for them.
It would be nice to have SelectMany in fluent mongodb's linq support to use mongodb in WCF data services.