I want to do manual sql queries but using the .net entity framework.
ex:
select from database where id == 20 ;
and no:
Item algo = new Item();
algo.name =
algo.lastName =
algo.Add();
understand me ????
I want to do manual sql queries but using the .net entity framework.
ex:
select from database where id == 20 ;
and no:
Item algo = new Item();
algo.name =
algo.lastName =
algo.Add();
understand me ????
Your question is understandable, although it is poorly written, first we go for examples:
using (var context = new BloggingContext())
{
var blogs = context.Blogs.SqlQuery("SELECT * FROM dbo.Blogs").ToList();
}
using (var context = new BloggingContext())
{
var blogs = context.Blogs.SqlQuery("dbo.GetBlogs").ToList();
}
You can also send parameters:
using (var context = new BloggingContext())
{
var blogId = 1;
var blogs = context.Blogs.SqlQuery("dbo.GetBlogById @p0", blogId).Single();
}
using (var context = new BloggingContext())
{
var blogNames = context.Database.SqlQuery<string>(
"SELECT Name FROM dbo.Blogs").ToList();
}
It beats me that this is what you are looking for:
using (var context = new BloggingContext())
{
context.Database.ExecuteSqlCommand(
"UPDATE dbo.Blogs SET Name = 'Another Name' WHERE BlogId = 1");
}
Reference: link