1

Suppose that we have three tables(Three Lists in SharePoint).The relations between tables are described by the following image.

enter image description here

I want to translate the following query to CAML query:

select c.* from TableB b inner join TableA a on 
b.TableAId=a.Id inner join TableC c on 
c.TableAId=a.Id
where b.Nam='ABC'
order by c.InsertDate 

I know that in CAML I can join first Table B and Table A and then with the resulted Table A.Id ,then query Table C. But this is two step fetch data and also I lose order by c.InsertDate in first query. And also if I want to limit only 10 result from TableC, In first CAML query(join query) I must fetch all data in first query.

Is there better approach to implement this query in SharePoint?

3

For such complex cases you might need to create DataContext and use Linq to SharePoint.. SPMetal command utility is used to create .CS code file for Entity Context..

Using this generated class you can easily query using LINQ..

Have a look at these:

Using LINQ to SharePoint

How to: Query Using LINQ to SharePoint

  • I forgot to say that we used LINQ to SharePoint in our project ,but it is really slow so that we decided to convert our LINQ queries to CAML ones.I have saw many posts that some users have problems using CAML in complex usecases(such as myself) and other developers suggest them to use LINQ.But i do not know whether they know that LINQ to SharePoint has performance problem? – Khosro Apr 20 '14 at 2:45
  • I must also to mention that ,according to this msdn.microsoft.com/en-us/library/ff798464.aspx ,we can see CAML generated queries from LINQ to SharePoint ,but in simple LINQ to SharePoint queries like queries those have "where" clause we can get CAML equivalent query,but in complex LINQ to SharePoint queries like the one in my post,it does not generate relevant CAML query. – Khosro Apr 20 '14 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.