我有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]
我已经验证项目中存在连接字符串。