C# EF Core-计算SQL或选择查询的导航集合属性
假设我有一个事务类,如下所示:C# EF Core-计算SQL或选择查询的导航集合属性,c#,entity-framework,entity-framework-core,C#,Entity Framework,Entity Framework Core,假设我有一个事务类,如下所示: public class Transaction { [Key] public int Id { get; set; } public int ForeignId { get; set; } public string Type { get; set; } public int Quantity { get; set; } public ICol
public class Transaction
{
[Key]
public int Id { get; set; }
public int ForeignId { get; set; }
public string Type { get; set; }
public int Quantity { get; set; }
public ICollection<Transaction> Takes { get; set; }
}
公共类事务
{
[关键]
公共int Id{get;set;}
公共int异化{get;set;}
公共字符串类型{get;set;}
公共整数数量{get;set;}
公共ICollection接受{get;set;}
}
我希望导航属性Takes
,它包含在当前事务
之后发生的类型为Take
的所有事务,并且具有相同的异化
这是事务数据的一个示例:
身份证件
异化
类型
量
1.
42
拿
50
2.
42
创造
10
3.
42
相关的东西
2.
4.
9
拿
3.
5.
42
拿
4.
6.
42
拿
5.
数据可以按顺序存储在数据库中。这取决于数据库。例如,SQL Server是多线程的,每次执行查询时都会以不同的顺序获得结果。我在您的案例中保证您获得按ID排序所需的最高ID的数字。顺便说一句,将事务作为类名或属性不是一个好主意,因为它可能与数据库事务类/属性冲突。EF Core仅支持基于FK的关系和导航,句号。从一开始就没有任务,不需要尝试,没有基于导航属性的解决方案。