score:2
Accepted answer
here's how you would write the query:
var query =
from c in db.vw_categories
join cl in db.vw_categorieslocalization on c.level equals cl.level into clo
from cl in clo.defaultifempty()
where (cl == null || cl.language == "en")
&& c.level.startswith("000")
&& c.level != "000"
select new
{
c.level,
name = cl == null ? null : cl.name,
c.quantity
}
to convert that to ienumerable<datarow>
maybe you could do something like this:
var datarows = query.select(r => {
var row = datatable.newrow();
row["level"] = r.level;
row["name"] = r.name;
row["quantity"] = r.quantity;
return row;
});
score:1
if using linq to sql:
var ctx = new somedatacontext();
from c in ctx.vw_categories
join cl in ctx.vw_categorieslocation
on c.level equals cl.level into g
from clv in g.defaultifempty()
where (clv == null || clv.language == "en")
&& c.level.contains("000%")
&& c.level != "000"
select new
{
c.level,
name = (clv != null) ? clv.name : default(string),
quantity = c.quantity
};
more info here: http://codingsense.wordpress.com/2009/03/08/left-join-right-join-using-linq/
Source: stackoverflow.com
Related Query
- Get linq to return IEnumerable<DataRow> result
- How can I get LINQ to return the object which has the max value for a given property?
- How to get linq `ForEach` statement to return data on the method call being made for each list object?
- why is this linq query return a boolean and not the first result of the select?
- How to execute stored procedure and get return result in MVC/EF/LINQ
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- How to get linq result as string array?
- Return one result from LINQ Query
- How can I get LINQ to return the index of the object which has the max value in a collection?
- how to get all columns from a linq result with a join
- LINQ Source Code Available
- Parallel Linq - return first result that comes back
- LINQ query return same result despite different datasources
- Return Datatype of Linq Query Result
- How to get Multiple Result Set in Entity Framework using Linq with C#?
- LINQ GroupBy return List as result
- LINQ Is it possible to get a method name without a return type via LINQ expression trees?
- Get result function in LINQ without translate to store expression
- Retrieve bool result by using LinQ code
- How to get SQL query into LINQ form in C# code
- StackOverflowException trying to return a Linq query result as a List through a WCF Service
- Linq (or SQL): Get a search query and sort it order by best result
- creating Linq to sqlite dbml from DbLinq source code
- Pass a property of a Linq entity in a method to set and get result
- Filter data in dataset using LINQ and get result as list of strings
- generic method to get linq result to datatable for select new with multiple selects
- C# LINQ How to get a data source from a db?
- How to Join in LINQ using Lambda expressions and get the result in DTO?
- Linq code doesn't return correct record
- Using LINQ query result for data source for GridControl c#
More Query from same tag
- Basic LINQ expression for an ItemCollection
- Change Join Type on a condition in LINQ
- Get a value using Ling to XML and where clause
- using Task.WhenAll and Linq Select new object
- Explain LINQ All() expression
- Easier Way (Linq) to Convert List Using Split
- Converting sql query to EF query- nested query in from
- Decimal.ToString not working if the value is zero
- LINQ NHibernate, latest related entity
- How can I filter a DataSource before applying it to a ListView
- Query returning the query, not a result
- cannot get a timespan to add to a datetime
- Adding paging and filtering to typical Linq Specification pattern?
- Using LINQ/Lambdas to copy a String[] into a List<String>?
- Load collection except another collection using linq
- How to sort multiple list properties?
- How to find (and remove) a nested object from a List
- Convert IGrouping to IList<Class>
- Linq doing a group in a lambda subselect
- Dynamic Linq Query where
- Query an XML using LINQ and excluding where an Attribute value is equal to that of an Element
- LINQ: Problem using DB with relations
- OrderBy IEnumerable property of class
- How to Preform foreach in a IEnumerable object
- How can this be achieved in LINQ?
- How to analyse LINQ queries
- LINQ To SQL Contains Case Sensitive Searching
- LINQ for getting the 5 latest records for each distinct name
- picking a DataRow Based on maximum of certain field and criteria using LINQ
- Incorrect data comes out when applying OrderBy to an int member of a model property?