0
squaresunion created
Hello, How to do a simple sql query withing the dbContext. I mean everything we usually used do not work: dbContext.Database.SqlQuery is not available. Why is this not available? How do to it?
Regards
5 Answer(s)
-
0
You can also create a custom repository for the entity. In custom repositories there's a shortcut method GetDbContext() to retrieve your DbContext.
public class SubscriptionPaymentRepository : AbpZeroTemplateRepositoryBase<SubscriptionPayment, long>, ISubscriptionPaymentRepository { public SubscriptionPaymentRepository(IDbContextProvider<AbpZeroTemplateDbContext> dbContextProvider) : base(dbContextProvider) { } public async Task UpdateMyDbWithSqlCommand() { await GetDbContext().Database.ExecuteSqlCommandAsync("Update myTable set MyField=1 where MyFilter=2"); } }
Have an answer to this question?
Log in
and write your answer.