defaultifempty

Default if empty with LINQ to entities

In a LINQ to entities expression like this: var vote = (from vote in db.Vote where vote.Voter.Id == user.Id select v).FirstOrDefault(); how do you you add a DefaultIfEmpty so that when there's no vote I'd get a default value? ...

Linq, Left Join and Dates...

So my situation is that I have a linq-to-sql model that does not allow dates to be null in one of my tables. This is intended, because the database does not allow nulls in that field. My problem, is that when I try to write a Linq query with this model, I cannot do a left join with that table anymore because the date is not a 'nullable...

why does DefaultIfEmpy throw NotSupportedException?

var defaultRole=ZAssociateRoles.Single(r=>r.RoleName=="Associate"); var allAssociates=(from a in ZAssociates join arm in Associate_role_maps on a.UserName equals arm.UserName into leftArm from la in leftArm.DefaultIfEmpty() join r in ZAssociateRoles on la.AssociateRoleId equals r.AssociateRoleId into leftOuterRole ...

Defaultifempty seems to work in linq to entities

I'm new to linq and linq to entities so I might have gone wrong in my assumptions, but I've been unknowingly trying to use DefaultIfEmpty in L2E. For some reason if I turn the resultset into a List, the Defaultifempty() works I don't know if I've inadvertantly crossed over into Linq area. The code below works, can anyone tell me why? ...

DefaultIfEmpty doesn't work

Why is array still null after queried by DefaultIfEmpty ? class Program { static void Main(string[] args) { Program[] array = new Program[5]; Program[] query = array.DefaultIfEmpty(new Program()).ToArray(); foreach (var item in query) { Console.WriteLine(item.ToString()); } ...

Why is this defaultIfEmpty choosing ienumerable<char> instead of string?

from a in mainDoc.XPathSelectElements("//AssembliesMetrics/Assembly/@Assembly") let aVal=a.Value where aVal.IsNullOrEmpty( )==false&&aVal.Contains(" ") select aVal.Substring(0, aVal.IndexOf(' ')) into aName ...