有人可以告诉我为什么在使用 select 语句后我的 where 语句中没有属性,例如
db.Select(x => x.Lft).Where(x => x.DepartmentId == id);
// missing properties in the where clause
你能帮我纠正我的代码来实现它吗请给我一个例子来说明如何实现这个谢谢
课程:
public class Department
{
public Department()
{
Products = new List<Product>();
}
public long DepartmentId { get; set; }
[Required(ErrorMessage="Please enter a name for the departments.")]
[DataType(DataType.Text)]
public string Name { get; set; }
[DataType(DataType.Text)]
[Required(ErrorMessage = "Please enter a valid url for the department.")]
public string Url { get; set; }
public int Lft { get; set; }
public int Rgt { get; set; }
public bool MenuItem { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
我的 DataContext 类
internal class DepartmentsTypeConfiguration : EntityTypeConfiguration<Department>
{
public DepartmentsTypeConfiguration()
{
Property(department => department.DepartmentId)
.HasColumnName("DepartmentId")
.HasDatabaseGeneratedOption(databaseGeneratedOption: DatabaseGeneratedOption.Identity);
Property(department => department.Name)
.HasColumnName("Name")
.IsRequired();
HasKey(key => key.DepartmentId)
.HasMany(x => x.Products)
.WithRequired(x => x.Department)
.WillCascadeOnDelete(true);
}
}
public class LeapFrogDataContext : DbContext
{
public DbSet<Department> Departments { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<ProductSpecification> ProductSpecifications {get; set;}
public DbSet<Specification> Specifications { get; set; }
/**/
static LeapFrogDataContext()
//: base("name=LeapFrogDataConnection")
{
//Database.SetInitializer(new LeapFrogInitializer());
//Database.SetInitializer(new DropCreateDatabaseIfModelChanges<LeapFrogDataContext>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new DepartmentsTypeConfiguration());
modelBuilder.Configurations.Add(new ProductsTypeConfiguration());
modelBuilder.Configurations.Add(new SpecificationsTypeConfiguration());
modelBuilder.Configurations.Add(new ProductSpecificationsTypeConfiguration());
base.OnModelCreating(modelBuilder);
}
}