Search code examples
mysqlasp.net-mvcodatalinq-to-dataset

How to retrieve data from two tables using join in Simple OData Client?


I'm using mvc application and simple OData to retrieve values from two tables. created object of ODataClient

ODataClient client = new ODataClient("http://localhost:65556/Dev");

Want to retrieve value from two table like in Sql we simply do like following

  select * from [Table1] t1 join [Table2] t2
  on t1.Id = t2.Id 
  where t1.[Title] = 'US'

Now In SimpleOdata I do not know about two table operation for one table we can simply do something like following

ODataClient client = new ODataClient("http://localhost:64576/Dev");  

var packages = await client
                .For<Table1>()
                .Filter(x => x.Title == "US")
                .FindEntriesAsync();
            foreach (var package in packages)
            {
                return package.Title;
            }
            return "test";

How can I correct above expression for two tables?


Solution

  • ODataClient client = new ODataClient("http://localhost:64576/Dev");  
    
    var packages = await client
    .For<Table1>()
    .Expand(x => x. Table2)
    .Filter(x => x.Title == "US")
    .FindEntriesAsync();
    
    foreach (var package in packages)
    {
         return package.Title;
    }
    return "test";