Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i write the below statement in LINQ

C#
XmlNode userNode = resultNode.SelectSingleNode("generalinfo", nsmgr);
               if (userNode != null)
               {
                   genInfoViewModel.StartDate = userNode.Attributes["effectivedate"] != null ? userNode.Attributes["effectivedate"].Value : string.Empty;
                   genInfoViewModel.TotRetailSquareFeet = userNode.Attributes["retailsqft"] != null ? userNode.Attributes["retailsqft"].Value : string.Empty;
                   genInfoViewModel.TotalSquareFeet = userNode.Attributes["totalsqft"] != null ? userNode.Attributes["totalsqft"].Value : string.Empty;
                   genInfoViewModel.CityPopulation = userNode.Attributes["citypopulation"] != null ? userNode.Attributes["citypopulation"].Value : string.Empty;
                   genInfoViewModel.GunLicense = userNode.Attributes["gunlicense"] != null ? userNode.Attributes["gunlicense"].Value : string.Empty;
                   genInfoViewModel.TaxRegistration = userNode.Attributes["taxregnum"] != null ? userNode.Attributes["taxregnum"].Value : string.Empty;
               }


What I have tried:

userNode.Attributes["effectivedate"]!=null?userNode.Attributes["effectivedate"].FirstChild
Posted
Updated 25-Apr-16 23:45pm
Comments
Tomas Takac 26-Apr-16 4:05am    
You can use LINQ to transform a sequence into another sequence. I don't see any such thing in your code. Maybe you are just not showing it all? I imagine you may be reading XML and creating view models out of it? Then you should post the whole thing so we see what's going on.
deepankarbhatnagar 26-Apr-16 5:24am    
You are using xml code here how you can implement LINQ here

1 solution

Linq tutorial

101 LINQ Samples in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900