Click here to Skip to main content
16,013,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want small example to display data in table using query string not using lambda or linq .

What I have tried:

i want example to learn how i used query string in mvc4
Posted
Updated 4-Apr-16 21:16pm

1 solution

If you mean a raw sql query, you can do something like this:

C#
using (var context = new MyContext()) 
{ 
    var items = context.Database.SqlQuery("SELECT * FROM dbo.MyTable").ToList(); 
}


You can check MSDN for examples on executing raw sql queries.
 
Share this answer
 
Comments
Member 12244977 5-Apr-16 7:32am    
can you tell me how i insert please or told me about link or site i can learn from it and thanks .
princektd 5-Apr-16 21:14pm    
Usually, the entity framework in MVC4 is used along with LINQ.That is the norm. However, Entity Framework does allow execution of raw queries for special circumstances, for example, if the query has to be generated dynamically or so. Of course, you can do the same with LINQ also. But anyway, the point is that you can execute raw queries.

Check these links for examples:
1) BinaryIntellect Knowledge Base: http://www.binaryintellect.net/articles/fbc96859-8a31-4735-baeb-7adcbc521b30.aspx
2) StackOverflow: http://stackoverflow.com/questions/16828974/how-to-execute-raw-sql-query-with-in-entity-framework

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900