Replacing empty values with a default value in a Linq to Entities query -


The links below will have a default value in the value given below in the entity query in x.Number if the query 0 office telephone objects Returns i x Have tried number ?? "555-1212" but there is an error in it.

  From the contacts. Where (a = & gt; a.ListName.Contains ("ANDUS")). (10) Select new (id = ciid, officetailfone = c. Telephone where (a => gt; telephone type .name is included ("office")). (X => New {x} .AreaCode, x.Number, x.TelephoneType, x.Primary})}   

I have tried to do something like this:

  from contact C where (a = & gt; a.ListName.Contains ("ANDUS")). (10) Select new {id = cid, office telephone = c. Cellphone where (a = & gt; one telephone type .name Select (x = & gt; New {x.AreaCode, x.Number, x.TelephoneType, x.Primary}). Defaulge ("Office"). I'm not sure how to push a default object in 'DefaultIFEmpty ()   

Use DefaultIfEmpty and pass a default installation with those basic values, which you want by default I if no rows Is returned.

Try it out like this:

  Conta Cts.Where (a => A.ListName.Contains ("ANDUS")). Take (10). Select (x = & gt; new {id = x.Id, OfficeTelephone = x.Telephones. Where (a = & gt; a.Telephone.Name.Contains ("Office")) Select (b = & gt; ; New telephone {b.AreaCode, b.Number, B. telephone type, B primary}}. Default effect (new telephone ())});   

Where I assume that typeof (x.Telephones) == type (list & gt; telephone & gt;)

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -