我有一个 GenericRepository,CourseRepository 继承自它,Entities 返回一个课程列表
public class CourseRepository : GenericRepositories<Course>, ICourseRepository
{
public CourseRepository(LearningSiteDbContext Context) : base(Context)
{
}
}
public class GenericRepositories<TEntity> : IGenericRepositories<TEntity> where TEntity : class, IEntity,new()
{
protected readonly LearningSiteDbContext context;
public DbSet<TEntity> Entities { get; set; }
public GenericRepositories(LearningSiteDbContext Context)
{
context = Context;
Entities = context.Set<TEntity>();
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我在 Razor Page 中运行这个处理程序时
public async Task OnGetAsync(int Id, CancellationToken cancellationToken)
{
var selectedCourse = await courseRepository.Entities.FindAsync(Id,cancellationToken);
Model = mapper.Map<CourseEditVm>(selectedCourse);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
实体类型“Course”使用单个键属性定义,但 2 个值传递给“DbSet.Find”方法
这是 Course …
asp.net-core asp.net-core-2.1 entity-framework-core-2.1 ef-core-2.1
我在数据库作业中遇到这个问题并需要回答这个问题:
哪位员工对购买次数最多的客户的销售额最高?
这些是我尝试编写这个查询
--select Customers.Firstname,Products.Name,Sales.Quantity from Customers
--inner join Sales
--on Customers.CustomerId=Sales.CustomerId
--inner join Products
--on Sales.productId=Products.ProductId
--where Products.Name like 'Mobile'
--Select Customers.CustomerId,max(COUNT(Customers.CustomerId)) As Customecount,Emploees.EmploeeId,max(COUNT(Emploees.EmploeeId))as EmploeeeCount from Emploees
--inner join Sales
--on Emploees.EmploeeId=Sales.EmploeeId
--inner join Customers
--on Customers.CustomerId=Sales.CustomerId
--group by Customers.CustomerId,Emploees.EmploeeId ,Count(Sales.productId)as productCount,Count(Emploees.EmploeeId)as emploeeCount,Count(Customers.CustomerId)as customerCount
select * from
(select Distinct Customers.CustomerId,Sales.productId,COUNT(Sales.productId)as CountProduct from Customers
inner join Sales
on Customers.CustomerId=Sales.CustomerId
inner join Emploees
on Emploees.EmploeeId=Sales.EmploeeId
group by Sales.productId,Emploees.EmploeeId,Customers.CustomerId,Sales.productId) as Result
--gr
Run Code Online (Sandbox Code Playgroud)
但这些都不起作用
请帮我写这个查询。