Answer the question
In order to leave comments, you need to log in
DB dependencies in EF Core in conjunction with using?
Actually, the question is, there is a telegram handler, I catch callbacks there and work out using switch cases in using (catching likes or dislikes), how can I throw dependencies into these uses? I searched on Google, it’s just how to add context to dependencies, but I didn’t even find how to use these dependencies in using, here is a piece of my code:
internal partial class TelegramHandler
{
const string channelId = "@linkd_1";
private async Task HandleCallbackQuery(CallbackQuery callbackQuery, CancellationToken cancellationToken)
{
switch (callbackQuery.Data)
{
case "post_id like":
{
using (var db = new MyContext())
{
var postData = db.Posts
.FirstOrDefault(x => x.MessageId == callbackQuery.Message.MessageId);
//var postData = conn.ExecuteReader($"SELECT * FROM PostData AS pd WHERE pd.MessageId = '{ callbackQuery.Message.MessageId }'").Parse<PostData>().FirstOrDefault();
if (postData == null)
{
return;
}
var reader = db.Votes.FirstOrDefault(x =>
((x.VoterId == callbackQuery.From.Id) && (x.PostDataId == postData.Id)));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question