Convert IQueryable to Custom Class
c#, linq, mvvm, silverlight
Solution
If it's a single `AddXferData`, then try:
return resultSet.First();
or
return resultSet.FirstOrDefault();
If it can return `null` (as in `ID` not found or something)
Problem
I have a LINQ query as below, ``` public AddXferData DisplayXferDataToBeModified(int ID) { try { var resultSet = (from items in DataContext.Transfers where items.Transfer_ID.Equals(ID) select new AddXferData { XferID = items.Transfer_ID, LogicalName = items.Logical_Name, RoutCode = items.Route_Code, Label = items.Label, OnNetDNA = items.On_Net_DNA, OnNetDNB = items.On_Net_DNB, FailMessage = items.Failure_Message, }); return resultSet; } catch (Exception ex) { throw ex; } } ``` But my resultSet asks for a Cast and the message I get is "Cannot implicitly convert type 'System.Linq.IQueryable' to 'ICMAdministration.Data.AddXferData'. An explicit conversion exists (are you missing a cast?) I need to cast the resultset to type AddXferData. Can you let me know how this can be achieved. Your help in this regard is very much appreciated. Regards, Raghu