The following code uses dbcontext.
var CurrentUser = await userManager.GetUserAsync(User);
var DefaultLanguageID = CurrentUser.DefaultLangauge;
var TestForNull = (from c in _classificationLevel.GetAllClassificationLevels()
join l in _classificationLevelLanguage.GetAllClassificationLevelLanguages()
on c.Id equals l.ClassificationLevelId
where c.ClassificationId == NewLevel.SuObject.ObjectId
&& l.LanguageId == DefaultLanguageID
select c.Sequence).Count();
While running it, I get the error the error
A second operation started on this context before a previous operation completed.
I am not sure why. I can imagine that the first operation is:
userManager.GetUserAsync(User);
and is still running while the next starts. Though it has the keyword await in front.
The other option I thought is that within the query two tables are retrieved and that it uses for both the same dbcontext.
1. _classificationLevel.GetAllClassificationLevels()
2. _classificationLevelLanguage.GetAllClassificationLevelLanguages()
Is this the reason for the error?
The methods behind these are:
public IEnumerable<SuClassificationLevelModel> GetAllClassificationLevels()
{
return context.dbClassificationLevel.AsNoTracking();
}
and
public IEnumerable<SuClassificationLevelLanguageModel> GetAllClassificationLevelLanguages()
{
return context.dbClassificationLevelLanguage;
}
I don't have an async / await on these. Should I and if so, how should I do that?
On a model level, the two models are related as shown in the code below:
public interface IClassificationAndStatusRepository
{
IEnumerable<SuObjectVM> GetAllClassifications();
IEnumerable<SuClassificationStatusModel> GetAllStatus();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…