I am new to C# and this may end up being a dumb question but i need to ask anyway.
Is there a mechanism with C# to deserialize a result from an executed SQL statement into a c# object?
I have a C# program that reads a table from an sql server storing the row in an object – i am assigning each column value to an object member manually so i was wondering if there is a way to serialize the row automagically into an object. Or even better, a whole table in a collection of objects of the same type.
My environment is C#, VS2010, .NET4, SQLServer2008.
The assumption is that i know the columns i need, it’s not a select * query.
A link to a neat example will also be appreciated.
Thanks.
If the columns named as per the table names, you can do this with LINQ-to-SQL without any mapping code – just using
ExecuteQuery:Additionally, the sql can be automatically parameterized using
string.Formatrules:Of course, you can also use the VS tools to create a typed data-context, allowing things like: