Set Fields dynamically in linq to xml Expression using C# in Razor application



I am trying to export the XML file from the database table using XElement. I am using EF 6.0 Code first.


I am preparing XML using XElement by below code



TooltypeXml = new XElement("ToolTypes", (from tbl in db.ToolType
where tbl.CreationDate >= objLastSyncByDevice.LocaltoServerLastAccessDate || tbl.LastModifieDate >= objLastSyncByDevice.LocaltoServerLastAccessDate
|| tbl.IsDeleted == true
select new { tbl.ToolTypeId, tbl.ToolTypeName, tbl.Action, tbl.UpdatedBy, tbl.CreationDate, tbl.CreatedBy, tbl.LastModifieDate, tbl.IsDeleted }).ToList().Select
(x => new XElement("ToolType", new XElement("ToolTypeName", x.ToolTypeName), new XElement("Action", x.Action), new XElement("UpdatedBy", x.UpdatedBy), new XElement("CreationDate", x.CreationDate), new XElement("CreatedBy", x.CreatedBy), new XElement("LastModifieDate", x.LastModifieDate), new XElement("IsDeleted", x.IsDeleted))));


So It does create the XML format successfully , what I want is how I can write my Linq expression so I don't need to specify each and every fields in expression to select. Because I always want all the fields from table and if I do change something in table I don't need to change anything in code. Please help asap. Thanks in advance.


Tiada ulasan:

Catat Ulasan