Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I directly execute SQL queries in linq

In C# with VS 2008,I have a query ,In this query i join more than one tables,so i don't know the type , I want to know how to directly run a sql query in linq .

IEnumerable<Type> results = db.ExecuteQuery<TYpe>("sql query")

My above query works fine but I want to avoid type, I want to write

var results = db.ExecuteQuery("sql query");

Is there any way to write it?

Thanks in advance.

like image 792
shamim Avatar asked Apr 12 '11 04:04

shamim


1 Answers

    var result = dataContext.ExecuteQuery<JobsDto>
                 ("Select JobID,JobName From jobs");

but make sure JobsDto has two properties JobID and JobName and there types the same type as the table columns

PS. DTO stand for Data Transfer Object

like image 65
HB MAAM Avatar answered Oct 23 '22 10:10

HB MAAM