Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么使用ToListSync不会产生任何结果?_C#_Linq_Asp.net Core Mvc_Entity Framework Core - Fatal编程技术网

C# 为什么使用ToListSync不会产生任何结果?

C# 为什么使用ToListSync不会产生任何结果?,c#,linq,asp.net-core-mvc,entity-framework-core,C#,Linq,Asp.net Core Mvc,Entity Framework Core,我有一个艰难的时间与此,所以我希望你能帮助 在我的GiftCertificateController.cs中(我在索引方法中使用了LINQ查询) 这是my DbContext中实体映射的摘录: entity.ToTable("CertificateMaster"); entity.Property(e => e.Id) .IsRequired() .HasColumnName("Id");

我有一个艰难的时间与此,所以我希望你能帮助

在我的GiftCertificateController.cs中(我在索引方法中使用了LINQ查询)

这是my DbContext中实体映射的摘录:

entity.ToTable("CertificateMaster");

            entity.Property(e => e.Id)
            .IsRequired()
            .HasColumnName("Id");

            entity.Property(e => e.CampaignId)
            .HasColumnName("CampaignId");

            entity.Property(e => e.CertificateId)
            .HasColumnName("CertificateId");
SQL中的数据库表名为dbo.CertificateMaster

非常感谢您的帮助。谢谢

编辑:

理想情况下,您希望先等待结果,然后将其传递给视图

public async Task<IActionResult> Index() {
    var gifts = await _context.GiftCertificates
        .Include(e => e.VoucherCampaigns)
        .Include(e => e.CouponBrand)
        .Include(e => e.CouponTypes)
        .ToListAsync();

    return View(gifts);
}
公共异步任务索引(){
var gifts=wait_context.GiftCertificates
.包括(e=>e.V)
.包括(e=>e.CouponBrand)
.Include(e=>e.CouponTypes)
.ToListAsync();
返回视图(礼品);
}

我不确定将鼠标悬停在“gives.toListSync()”上是否是检查结果的正确方法,因为它是异步的,并且包含“Include”语句,所以请尝试在单独的一行中进行检查;比如:var giftsList=wait gifts.ToListAsync()然后检查giftsList的值。我按照你说的做了,我认为这不是问题所在,因为在调试模式下,在其他工作的控制器中,我可以通过将鼠标悬停在var.ToListAsync()上来查看db属性。尽管它不是在一个变量中。我已经用你建议的输出编辑了原始问题。你能给我们分享一个演示项目来重现你的问题吗,因为它似乎更具体到这个控制器?
entity.ToTable("CertificateMaster");

            entity.Property(e => e.Id)
            .IsRequired()
            .HasColumnName("Id");

            entity.Property(e => e.CampaignId)
            .HasColumnName("CampaignId");

            entity.Property(e => e.CertificateId)
            .HasColumnName("CertificateId");
public async Task<IActionResult> Index() {
    var gifts = await _context.GiftCertificates
        .Include(e => e.VoucherCampaigns)
        .Include(e => e.CouponBrand)
        .Include(e => e.CouponTypes)
        .ToListAsync();

    return View(gifts);
}