Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"the method join is not supported" with Tridion OData service & Linq

I'm trying to a join CustomMeta & PageContents to select a specific page via some metadata that has been set, but I'm getting a "the method join is not supported" error. I think the issue is with my linq statement, as the error happens before anything gets sent to the OData service. But what is the issue exactly? The linq statement looks fine to me:

    var pages2 = (from p in cds.PageContents
    join m in cds.CustomMetas on p.PageId equals m.ItemId
    where m.ItemType==64 && m.KeyName=="SomeKey" && m.StringValue=="SomeValue"
    select p).ToList<SDLODataClient.SDLOData.PageContent>();

UPDATE 1

This Tridion OData article has an example of a join but some of the MS Linq to OData articles I'm reading seem to suggest that joins aren't supported in Linq to OData (here)

like image 851
Mr Smith Avatar asked Nov 14 '12 21:11

Mr Smith


2 Answers

To my knowledge, LINQ queries against Data Services (OData) does not support several methods. The one you are using is join is also falls under the same category hence you are seeing the error even though the syntax is very valid from LINQ point of view. join falls under "Projection and filtering operators" which is not supported query with LINQ against OData .

Here is the link that explains all the unsupported methods (Refer section - Unsupported LINQ Methods)

http://msdn.microsoft.com/en-us/library/ee622463(v=vs.100).aspx

Back to your question, I am not quite how to achieve what you are looking for but I would try the following (you might have to get the results in multiple iterations):

  • Get the list of Page IDs that match the custom meta query (sample snippet - not tested)
_client.CustomMetas.Where (
 m => m.KeyName == "somekey" && m.StringValue == "somevalue" && m.ItemType == 64)
.ToList();
  • Now you could query Page Contents using the above page ids. You might have build the filter type query for each page id.

Hope this helps.

like image 70
Ram G Avatar answered Sep 28 '22 12:09

Ram G


Have you tried using the concept of expand ?

In OData service we do not have the join query but there is Expand keyword, wherein two entities (tables) that have a foreign key relationship can be used together to get a result set. It works as follows:

from item in table1.Expand(table2).AsEnumerable()
where (item.property1.Equals("x") & item.table2[0].prop2.Equals("y"))
select item

Here the second entity is exposed as an property of the first entity.

like image 33
user1640707 Avatar answered Sep 28 '22 11:09

user1640707