5

I'm trying to to do include and group in in one sentence

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

but when I check the result at debug I cant see any of the include values

I tried to do in another way

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

this is the classes : Track

  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; }
}

Service

      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; }
}

but the result is the same

thanks

miki

MIkCode
  • 2,655
  • 5
  • 28
  • 46

3 Answers3

3

You also need to put include in the end.

Like this...

var instanceIdList = context.Tracks
                            .GroupBy(x => x.ServiceId)
                            .Take(top)
                            .Include("Services");
Beakie
  • 1,948
  • 3
  • 20
  • 46
activebiz
  • 6,000
  • 9
  • 41
  • 64
1

You have not defined any navigation property for Services in your Track class, you need to add the following property.

public virtual ICollection<Service> Services { get; set; }
Asif Mushtaq
  • 13,010
  • 3
  • 33
  • 42
0

Your Track class has no member accessor called service, so

Include("Services")

won't work.

You need to link to Service from Track, e.g.

public Service Services {get;set;}
Justin Harvey
  • 14,446
  • 2
  • 27
  • 30