Running DevForce 6.0.9 under Silverlight 4.
I have a POCO that is roughly structured like this (it's in my Silverlight domain model project and linked in the BOS domain model project):
[DataContract] public class PasSummary : IHasEntityAspect, IKnownType { [Key] public Guid Id { get; set; } [DataMember] public PasNumber PasNumber { get; set; }
[DataMember] public int Number { get; set; }
[DataMember] public string Description { get; set; }
[DataMember] public string Function { get; set; }
[DataMember] public Decimal TotalHours { get; set; } [DataMember] public IEnumerable<Project> Projects { get; set; }
[IgnoreDataMember] public EntityAspect EntityAspect { get; set; } }
|
I have an Async projection that roughly looks like this:
var getEntriesForWeekOp = Manager.TimeSheetEntries .Where(p => p.TimeSheet.UserId == _currentUser.Id && p.TimeSheet.WeekEndingDate == date.Date) .Include("TimeSheet") .Include("Project.PasNumber.PasFunction") .GroupBy(timeSheetEntry => timeSheetEntry.Project.PasNumber) .Include("Projects.PasNumber.PasFunction") .Select(timeSheetEntries=> new PasSummary{ TestObject = timeSheetEntries.ToList(), PasNumber = timeSheetEntries.FirstOrDefault().Project.PasNumber, Number = timeSheetEntries.FirstOrDefault().Project.PasNumber.Number, Description = timeSheetEntries.FirstOrDefault().Project.PasNumber.Description, Function = timeSheetEntries.FirstOrDefault().Project.PasNumber.PasFunction.Name, Projects = timeSheetEntries.Select(entry=>entry.Project).Distinct().ToList(), TotalHours = timeSheetEntries.Where(ts=>ts.ActualHoursForWeek.HasValue) .Select(tse=>tse.ActualHoursForWeek.Value).Sum() }) .ExecuteAsync();
|
Problem 1: (Navigation Properties)
The PasNumber is a entity type. It has a navigation property called PasFunction. If I project PasNumber into PasSummary's PasNumber property all the navigation properties are null. Ommiting or adding the includes has no effect. However if I project the navigation property values (Such as in the above Function property) the values feeds in fine. When using a fake entity manger backing store the PasFunction navigation property is retained.
Problem 2 : Projecting collections differences when using a fake entity manager backing store:
The assignment of the "Projects" property in PasSummary in the above projection throws with the following exception when using a real entity manager:
LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[ProjectVisionModel.Project] ToList[Project](System.Collections.Generic.IEnumerable`1[ProjectVisionModel.Project])' method, and this method cannot be translated into a store expression.
|
If I ommit the .ToList() the assignment works fine, but then when using the fake entity backing store causes the following exception:
Type 'System.Linq.Enumerable+<DistinctIterator>d__81`1[ProjectVisionModel.Project]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types. |
So it seems the fake backing store hates ommiting the .ToList() and the real entity manager hates it when the .ToList() is there.
Any feedback you could provide on the recommended way to deal with these issues would be appreciated, thanks.