I have two Entities ItemChange
and PK
:
[Table("Sync_Changes")]
public class ItemChange
{
public Guid AgentId { get; set; }
public DateTime ChangeTime { get; set; }
[Required]
public string Descriminator { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid ID { get; set; }
[NotMapped]
public object Item { get; set; }
public virtual ICollection<PK> PKs { get; set; }
public virtual ChangeType State { get; set; }
}
And the PK class:
[Table("Sync_PKs")]
public class PK
{
public PK(string key, object value)
{
Key = key;
Value = value?.ToString();
ValueType = value?.GetType().Name;
}
[Key]
[Column(Order = 0)]
[ForeignKey(nameof(Change))]
public Guid ChangeId { get; set; }
[Key]
[Column(Order = 1)]
public string Key { get; set; }
[Required]
public string Value { get; set; }
[Required]
public string ValueType { get; set; }
public virtual ItemChange Change { get; set;
}
I want to group the ItemsChange
based on the PKs, for example i have two ItemChange that have the Pks [({Key="Id",Value="1"},{Key="GroupId",Value="2"})]
and the ChangeType [Created,Updated].
i want to know how to do this with Linq, or Mysql Script. Screenshots of the both tables: Changes that i want to group theme base on the pks. PKs