EF Core + MVC 6 + .NET Core RC2 - EF 不返回结果



实体框架核心没有返回任何结果。 我一直在远近寻找。 我发现一些教程说一件事,而另一些则说另一件事。这是我到目前为止所拥有的:

买家.cs

[Table("DealerCustomer", Schema = "dbo")]
public class Buyer
{
    [Key]
    public int DealerCustomerKey { get; set; }
    public int DealerId { get; set; }
}

买家语境.cs

public class BuyerContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder options)
    {
        options.UseSqlServer("db connection string here");
    }
    public DbSet<Buyer> Buyers { get; set; }
}

启动.cs>配置服务功能

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddApplicationInsightsTelemetry(Configuration);
    services.AddDbContext<BuyerContext>(options =>
        options.UseSqlServer("db connection string here");
    services.AddMvc();
}

现在我正在尝试从我的买家控制器加载买家数据.cs

[Route("api/[controller]")]
public class BuyersController : Controller
{
    private BuyerContext _context;
    public BuyersController(BuyerContext context)
    {
        _context = context;
    }
    [HttpGet]
    public IEnumerable<Buyer> Get()
    {
        System.Diagnostics.Debug.WriteLine("getting buyers");
        System.Diagnostics.Debug.WriteLine(_context.Buyers);
        return _context.Buyers;
    }
}

当我加载页面时,这一切都返回了空括号,而不是买家列表。 但是,该表中有超过 1000 行 (dbo.经销商客户)。 我知道我有两个地方添加数据库连接字符串,但教程一直显示两种方法,当我只在启动时.cs我收到有关_context的错误。 我可以让一切看起来都很漂亮,现在我只想要一个良好的连接,这样我就有了一个工作的起点。

我发现超时,因为其中一个小数字段返回 null。

EF 核心超时为空响应

最新更新