views:

35

answers:

2

I have a dynamic sql query which contains more than one table joined. Normally I get this query to a datatable and use it. For now I want to get result of this query to a list object. Does anyone help me about this case?

+1  A: 

You'll have to loop through the rows of the datatable, populate the column values to the properties of an object, add the object to the list and then return the list. Alternatively you could consider using a ORM tool like NHibernate.

Raj
If I have many rows returned from the query, it will take many time to perform this.
mavera
+1  A: 

If this query does not change very much you could create a stored procedure from it and implement the stored procedure in the Linq2SQL designer. This would give you the ability to just write

var MyResult = context.spMyStoredProcedure(var1, var2);

If I'm not completely wrong... Writing from memory ;)

Christian W