I am using LinqToSql on a project, and Ria services to expose it as an IQueryable.
I want to send my Product table along with its child tables (e.g. ProductStatus, ProductCategory)
To do this I am using the standard
public IQueryable ProductSelect() {
DataLoadOptions loadOpts = new DataLoadOptions();
loadOpts.LoadWith<Product>(p => p.ProductStatus);
loadOpts.LoadWith<Product>(p => p.ProductCategory);
this.DataContext.LoadOptions = loadOpts;
return this.DataContext.Products; }
Unfortunately this is creating inner joins, not left joins. There isn’t referential integrity on the tables (I can’t add it in).
This means if the there isn’t a matching record in the child table, then the product will not be selected.
Does anyone know how to change this to be a left join?
Found the answer. In the DBML file where I have the tables and the associations. It is related to the foreign key Ids.
If the foreign key is not nullable, then it does an inner join.
if you make the field nullable, then it will do a left join.