小编Ber*_*rip的帖子

Asp.net Core Linq 查询花费太多时间

我有一个 linq 查询,需要 31 秒。这是我第一次收到这么晚的询问,我不知道该怎么办。让我向您展示我的查询:

        public IEnumerable<WebFairField> WebFairFieldForFair(Guid ID)
        {
            return TradeTurkDBContext.WebFairField.Where(x => x.DataGuidID==ID)
             .Include(x => x.Category)
             //
             .Include(x=>x.FairSponsors)
             .ThenInclude(x=>x.Company)
             .ThenInclude(x=>x.FileRepos)
             //
             .Include(x=>x.WebFairHalls)
             .ThenInclude(x=>x.HallSeatingOrders)
             .ThenInclude(x=>x.Company)
             .ThenInclude(x=>x.FileRepos)
             //
             .Include(x=>x.HallExpertComments)
             .Include(x=>x.Products)
             .Include(x=>x.FairSponsors)
             .AsNoTracking().ToList();
        }
Run Code Online (Sandbox Code Playgroud)

我确信这是一个正确的查询,但我不知道为什么该查询花费了太多时间。

谢谢你的帮助!!

linq asp.net asp.net-mvc ef-code-first entity-framework-core

2
推荐指数
1
解决办法
1444
查看次数

Asp.Net Core 通用存储库模式软删除

我正在尝试在我的中创建一个Soft Delete操作Repository,但我必须在不创建任何接口或类的情况下执行此操作。首先让我向您展示我的方法,

public void Delete(T model)
{
    if (model.GetType().GetProperty("IsDelete") == null )
    {
        T _model =  model;
        _model.GetType().GetProperty("IsDelete").SetValue(_model, true);//That's the point where i get the error
        this.Update(_model);
    }
    else
    {
        _dbSet.Attach(model);
        _dbSet.Remove(model);
    }
}

Run Code Online (Sandbox Code Playgroud)

我遇到了Object reference not set to an instance of an object.例外。我当然知道这意味着什么,但我就是不明白,也不知道该怎么办。我不确定是否有更好的方法。

谢谢阅读!

伙计们,你们真的必须看看我在哪里收到错误。我正在编辑我的问题。


 public abstract class Base
    {
        protected Base()
        {
            DataGuidID = Guid.NewGuid();
        }
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid DataGuidID { get; set; }
        public int? CreatedUserId { get; set; } 
        public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net entity-framework-core asp.net-core-mvc asp.net-core

2
推荐指数
1
解决办法
946
查看次数