I’m using Linq to create a list of objects. Shown below is the expression I am using. The problem I have is that at runtime it isn’t happy with the “RawXMLDocument = XElement.Parse(t.Message)” line. The “RawXMLDocument” property takes an XElement. Is there a way to convert the string version of the XML (held in Message) into an XElement as shown below?
var transactionList = (from t in ctx.Transactions
where t.MessageRecievedAt >= Start && t.MessageRecievedAt <= End
select new TerminalTransactionMessage
{
DeviceId = t.DeviceId,
RawXMLDocument = XElement.Parse(t.Message),
TransactionTime = t.EventTime_Local
}).ToList();
Is the problem that it’s trying to do it in SQL? If so, you need to just separate out the bits to do in SQL and the bits to do in LINQ to Objects. Try this: