gpt4 book ai didi

c# - Entity Framework linq 包含和分组

转载 作者:行者123 更新时间:2023-12-02 01:02:47 24 4
gpt4 key购买 nike

我正在尝试在一个句子中包含和分组

var instanceIdList = context.
Tracks.
Include("Services").
GroupBy(x => x.ServiceId).
Take(top);

但是当我在调试时检查结果时,我看不到任何包含值

我尝试用另一种方式来做

var objectContext = ((IObjectContextAdapter)context).ObjectContext;
var set = objectContext.CreateObjectSet<Track>();
var instanceIdList = set.Include("Services").GroupBy(x => x.ServiceId);

这是类(class): 追踪

  public partial class Track
{
public long Id { get; set; }
public System.Guid ServiceId { get; set; }
public Nullable<System.Guid> ServiceInterfaceId { get; set; }
public Nullable<System.Guid> ProviderId { get; set; }
public System.Guid ServiceInstanceId { get; set; }
public System.Guid ActivityParentId { get; set; }
public System.Guid ActivityInstanceId { get; set; }
public int ActivityType { get; set; }
public int ServiceRole { get; set; }
public int TrackOrder { get; set; }
public System.DateTime Datetime { get; set; }
public Nullable<System.Guid> MessageId { get; set; }
public int Status { get; set; }
public Nullable<int> ESBErrorCode { get; set; }
public Nullable<int> ESBTecnicalErrorCode { get; set; }
public string ErrorDescription { get; set; }
public string PortName { get; set; }
public string MachineName { get; set; }
public string ConsumerId { get; set; }
public string ExternalId { get; set; }
public string ConsumerMachineName { get; set; }
public int ServiceBehavior { get; set; }

public virtual Message Message { get; set; }
}

服务

      public partial class Service
{
public Service()
{
this.Providers = new HashSet<Provider>();
this.ServiceInterfaces = new HashSet<ServiceInterface>();
}

public System.Guid ServiceId { get; set; }
public string ServiceName { get; set; }
public string ServiceNumber { get; set; }
public Nullable<System.Guid> ModelSchemaId { get; set; }

public virtual ICollection<Provider> Providers { get; set; }
public virtual ICollection<ServiceInterface> ServiceInterfaces { get; set; }
}

但是结果是一样的

谢谢

三木

最佳答案

您还需要将 include 放在最后。

像这样...

var instanceIdList = context.Tracks
.GroupBy(x => x.ServiceId)
.Take(top)
.Include("Services");

关于c# - Entity Framework linq 包含和分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12934290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com