Joins over Odata
– Joins Categories and products table/vategory with the combination of categoryid and product id
– Get the collection/records of Categories and products table/category based on the condition
– Get only selected field/column value based on the join condition
– Get selected filed/column value of the Products table/category based on joining condition
– Get only a value string (with no xml tags) of selected field/column value based on joining condition
– Get the collection/records linked with products table/category
– Works same as the above query which identifies the category table/category and gets the collection/records associated with products table
– Get selected fields/entity of all the collection/records of the products table/category associated with categories table/category
– Get selected fields/entity of the first collection/record of products table/category associated with categories and order_details table/category
– Get selected filed/column value of the Products table/category based on joining and search condition in which OrderID=10285
– Get selected filed/column value of the Products table/category based on joining and search condition in which price greater than 200
Odata formats:
– Get the collection/records of the products table/category with atom format (default fomat)
– Get the collection/records of the products table/category with json format
For more information please click here
With all these information hope you get a good idea on OData and in another corner you might be scratching your head thinking all the queries are written only through url (http context) but how to use this in .net code-behind with LINQ.
We can also use the http context call in code-behind but obviously we can use our OData web service with LINQ in code-behind.
Here we go with the process.
Add a web page to your web project. Add a web service reference which you have created earlier to your project. Then write the code in your web page code behind file as follows
var serviceURI = new Uri("http://www.yourserviceurl.com/WcfDataService1.svc"); var context = new NorthwindService.NORTHWNDEntities(serviceURI); //Get all records/collection of the products table/category var query = (from el in context.Products select el).toList(); //Get the top record/collection of products table/category var query = (from el in context.Products select el).FirstOrDefault(); //Get all top records/collection of the products table/category by joining category, supplier and order_details table/category var query = (from el in context.Products.Expand("Category,Supplier,Order_Details") where el.ProductID.Equals(1) select el).FirstOrDefault(); //Search the result collection of the last quesry with orderID var searchres = (from el in query.Order_Details where el.OrderID.Equals(10285) select el).FirstOrDefault();
Once you get the required collection with the join you can search and do other linq operations. Please feel free to contact me @Raghav for any queries