In your case, you are not grouping the records so don't use your solution. You can use the solution from ScottS or use the query below var res = from p in places select new { Place = p. Place, CityName = (from c in cities where p.
CityCode == c. CityCode select c. CityName).
DefaultIfEmpty("NO NAME"). ElementAtOrDefault(0) }.
In your case, you are not grouping the records so don't use your solution. You can use the solution from ScottS or use the query below. Var res = from p in places select new { Place = p.
Place, CityName = (from c in cities where p. CityCode == c. CityCode select c.
CityName). DefaultIfEmpty("NO NAME"). ElementAtOrDefault(0) }.
Here is a linq query version var noCity = new City {CityName = "NO NAME"}; var anotherway = from p in places join c in cities on p. CityCode equals c. CityCode into merge from c in merge.
DefaultIfEmpty(noCity) select new { p. Place, c. CityName }; I think the use of DefaultIfEmpty() makes it a little more clear.
All in all, I find outer joins in linq pretty darn confusing. It's one of the few places where I find SQL queries dramatically superior.
Yeah, I also agree! But I cant use SQL query there in my example. – Akshay J Feb 25 '10 at 9:53.
We can achieve the same in LINQ to Objects by using the DefaultIfEmpty Operator, and handling the null instance in the Select projection. Join o in orders on c. Key equals o.
If joinedLists is empty, partDefaults will be null, so you can't dereference it. Try this: UoM = partDefaults == null? "Null" : partDefaults.
UoM? "Null", ABC = partDefaults == null? "Null" : partDefaults.
ABC? "Null (as the last two bits of your projection) Note that this copes with either partDefaults being null or the relevant property being null.
If joinedLists is empty, partDefaults will be null, so you can't dereference it. Try this: UoM = partDefaults == null? "Null" : partDefaults.
UoM? "Null", ABC = partDefaults == null? "Null" : partDefaults.
ABC? "Null", (as the last two bits of your projection). Note that this copes with either partDefaults being null or the relevant property being null.
Cool, thanks :) – sparkymark75 Mar 25 at 15:19.
Refer this or this examples to learn more and your case it would be something like this.
Here is a great breakdown of the left outer join.
EditSimulating an Outer JoinA normal join using the Join Standard Query Operator performs an inner-join, where outer elements without any inner elementsd are not included in the result. This may not be the desired behaviour. In database parlance, retrieving all outer elements, even when there is no matching record(s) on the inner sequence is called Outer Join.
We can achieve the same in LINQ to Objects by using the DefaultIfEmpty Operator, and handling the null instance in the Select projection. Join o in orders on c. Key equals o.
OrderNumber = ((o == null)?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.