-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Data.Entity.Database.SqlQuery<TElement> was really useful. Why is it not available in .NET Core? #12887
Comments
@jenergm, i suppose it’s just simple sample because i do not see any benefits of dynamic sql building versus linq queries. EF will create parameters and SQL without any problem. public IHttpActionResult FindPaged(MyViewModel dto)
{
using (MyContext myContext = new MyContext())
{
var query = myContext.MyTable.AsNoTracking().Where(t => !t.Disabled);
if (!string.IsNullOrEmpty(dto.name))
query = query.Where(t => t.Name.Contains(dto.Name));
if (dto.capacity != null)
query = query.Where(t => t.Capacity > dto.Capacity);
if (dto.dir == null)
query = query.OrderBy(t => t.Name);
else
query = query.OrderByDescending(t => t.Name);
query = query.Skip(pageNumber * pagesSize).Take(pageSize);
var result = query.Select(t => new MyViewModel
{
Id = t.Id,
Name = t.Name,
Capacity = t.Capacity,
Version = t.Version
});
return Ok(result.ToList());
}
} And if you need some dynamic querying like ordering by different columns - there is DynamicLinq. |
Hi Svyatoslav Danyliv, Thanks for answer and participate! Thanks in advance! |
@jenergm, you have several options before EF support this again.
|
I understood... but we really would like something in EntityFrameworkCore as there is in EntityFramework of .NET Framework. |
@jenergm Is there some reason that FromSql with QueryTypes doesn't work for you? |
Hi Arthur, Thanks for enter in this topic. What is easier for us was using raw queries like does SqlQuery from EntityFramework as we had. For example, it wasn't necessary use a DbSet, just a Context, a SqlQuery and a ViewModel Class and it wasn't necessary do any map.
Best regards, |
Hi Arthur, Thanks for answer me! I wish it can be possible in a next future version. Cheers, |
any news? |
You can use this: #1862 (comment) |
Dear all,
For .NET Core development and performance is quite important that we can run SQL Native queries and fill ViewModels directly.
We have created a lot of helpers in .NET Framework using that like this:
In that example, SqlQueryPage uses SqlQuery internally... I can run any query with any parameters and use any ViewModels matching.
Technical details:
Best regards,
Jener Garcia Menezes
System Architect at PROSEGUR S/A
The text was updated successfully, but these errors were encountered: