I have a LINQ to SQL query function combinding to tables, but the function gives an error on “return res.ToList();”.
- imo_no is int
- position_cordinates is String
- vessel_id is int
- equipment is String.
My function:
List<T> GetAllInitialize()
{
PositionDataClassesDataContext context = new PositionDataClassesDataContext();
var res = from positions in context.it_positions
join vessels in context.it_vessels on positions.imo_no equals vessels.imo_no
select new { positions.imo_no, positions.position_cordinates, vessels.vessel_id, vessels.equipment };
return res.ToList();
}

Although you can use anonymous types or collections of objects of anonymous type locally with static typing, there is no way to return them from a function without losing the information about their static type.
If you cannot or for some reason prefer not to create a named class to hold the return data, you need to either return
List<dynamic>, orList<object>. Both these approaches have their drawbacks:dynamicwill be slower than a comparable statically-typed object, whileSystem.Objectwould not let you do much with the data that you get back.The best solution would be creating a named return type:
Now your query will look like this:
The return type of your method would change to
List<PositionData>.