查询数据库时,EF 6.2不返回结果

时间:2018-04-28 19:20:03

标签: c# sql-server entity-framework

我有DbContext

public class SomeDbContext : DbContext
{
   public SomeDbContext () : base("SomeConnectionString")
   {}

   public DbSet<Car> Cars { get; set; }

   protected override void OnModelCreating(DbModelBuilder modelBuilder)
   {
      base.OnModelCreating(modelBuilder);
   }
}

但是当我想查询数据库Cars时,不会返回任何内容。

示例:

var context = new SomeDbContext();
var cars = context.Cars.ToList(); // Nothing gets returned here...

但是,如果我将SQL查询粘贴到SSMS,则返回项目就好了。

从Visual Studio调试器获取的SQL查询:

SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[Engine] AS [Engine],
    [Extent1].[StartTime] AS [StartTime], 
FROM 
    [dbo].[Cars] AS [Extent1]

我已经验证项目中存在连接字符串。

0 个答案:

没有答案