背景-我正在使用实体框架代码版本2.1.4-rtm-31024
签出代码清单1 -问题(根据Build Engine 15.9女士)是GetAllMakes调用.ToList,但对于VehicleBake的DbSet不存在“ ToList”方法。 (请查看代码清单2 )以查看_vehicleContext.VehicleMakes
的实现。为什么会出现编译错误?这对我来说毫无意义,因为我可以在代码的其他地方调用VehicleMakes.ToList()(没有编译器错误)完全没有问题-请参见清单3 作为示例。
代码列表1
emit stopThread();
代码列表2
using System.Collections.Generic;
namespace CarPriceComparison.Models
{
public class VehicleRepository : IVehicleRepository
{
private VehicleContext _vehicleContext;
public VehicleRepository(VehicleContext dbContext_)
{
_vehicleContext = dbContext_;
}
public IEnumerable<VehicleMake> GetAllMakes()
{
return _vehicleContext.VehicleMakes.ToList();
}
}
}
代码列表3
namespace CarPriceComparison.Models
{
public class VehicleContext : DbContext
{
private IConfigurationRoot _config;
public VehicleContext(IConfigurationRoot config_, DbContextOptions
options_) : base(options_)
{
_config = config_;
}
public DbSet<VehicleMake> VehicleMakes {get; set;}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlServer(_config["ConnectionStrings:VehicleContextConnection"]);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<VehicleModel>()
.HasOne(p => p.Make)
.WithMany(b => b.Models)
.HasForeignKey(p => p.VehicleMakeForeignKey)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
}
}
}
答案 0 :(得分:1)
我认为您缺少using语句。
exports.module