- Home
- LLBLGen Pro
- Bugs & Issues
Derived Element projection null handling
Joined: 04-Dec-2014
Right now derived element projection cannot handle prefetch that resulted in null properties in the Entity. If a table has a value null in a FK column, it will blow up.
Is this by design?
This sample is using the ReadOnly template.
private static System.Linq.Expressions.Expression<Func<Inspection.Data.EntityClasses.WeeklyPlanDayEntity, Inspection.ViewModel.DtoClasses.WeeklyPlanDay>> CreateProjectionFunc()
{
return p__0 => new Inspection.ViewModel.DtoClasses.WeeklyPlanDay()
{
Day = p__0.Day,
Id = p__0.Id,
PlanDayStatus = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.PlanDayStatus()
{
ArabicName = p__0.PlanDayStatus.ArabicName,
EnglishName = p__0.PlanDayStatus.EnglishName,
Id = p__0.PlanDayStatus.Id,
},
PlanDayStatusId = p__0.PlanDayStatusId,
StaffId = p__0.StaffId,
Week = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.Week()
{
EndDate = p__0.Week.EndDate,
StartDate = p__0.Week.StartDate,
Year = p__0.Week.Year,
},
WeekId = p__0.WeekId,
WeeklyPlanDayTasks = p__0.WeeklyPlanDayTasks.Select(p__1 => new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTask()
{
PlanTask = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTaskTypes.PlanTask()
{
Id = p__1.PlanTask.Id,
InspectionOrganizationId = p__1.PlanTask.InspectionOrganizationId,
InspectionType = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTaskTypes.PlanTaskTypes.InspectionType()
{
ArabicName = p__1.PlanTask.InspectionType.ArabicName,
EnglishName = p__1.PlanTask.InspectionType.EnglishName,
Id = p__1.PlanTask.InspectionType.Id,
IsLabor = p__1.PlanTask.InspectionType.IsLabor,
IsOsh = p__1.PlanTask.InspectionType.IsOsh,
},
InspectionTypeId = p__1.PlanTask.InspectionTypeId,
Organization = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTaskTypes.PlanTaskTypes.Organization()
{
Id = p__1.PlanTask.Organization.Id,
Name = p__1.PlanTask.Organization.Name,
TotalNumberOfEmployees = p__1.PlanTask.Organization.TotalNumberOfEmployees,
},
PlanActivity = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTaskTypes.PlanTaskTypes.PlanActivity()
{
ArabicName = p__1.PlanTask.PlanActivity.ArabicName,
EnglishName = p__1.PlanTask.PlanActivity.EnglishName,
Id = p__1.PlanTask.PlanActivity.Id,
},
PlanActivityId = p__1.PlanTask.PlanActivityId,
PlanTaskParticipants = p__1.PlanTask.PlanTaskParticipants.Select(p__2 => new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTaskTypes.PlanTaskTypes.PlanTaskParticipant()
{
ContactInfo = p__2.ContactInfo,
Id = p__2.Id,
Name = p__2.Name,
Note = p__2.Note,
Person = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTaskTypes.PlanTaskTypes.PlanTaskParticipantTypes.Person()
{
CreatedByUserId = p__2.Person.CreatedByUserId,
DateCreated = p__2.Person.DateCreated,
Email = p__2.Person.Email,
FirstName = p__2.Person.FirstName,
Id = p__2.Person.Id,
IsActive = p__2.Person.IsActive,
LastName = p__2.Person.LastName,
MobilePhone = p__2.Person.MobilePhone,
},
PersonId = p__2.PersonId,
PlanTaskId = p__2.PlanTaskId,
StaffId = p__2.StaffId,
}).ToList(),
TaskType = new Inspection.ViewModel.DtoClasses.WeeklyPlanDayTypes.WeeklyPlanDayTaskTypes.PlanTaskTypes.TaskType()
{
ArabicName = p__1.PlanTask.TaskType.ArabicName,
EnglishName = p__1.PlanTask.TaskType.EnglishName,
Id = p__1.PlanTask.TaskType.Id,
},
TaskTypeId = p__1.PlanTask.TaskTypeId,
TimeOfInspection = p__1.PlanTask.TimeOfInspection,
},
WeeklyPlanDayId = p__1.WeeklyPlanDayId,
}).ToList(),
};
}
Joined: 21-Aug-2005
Which LLBLGen Pro Version, and which runtime library version (build no.)?
I believe the following thread was discussing is a similar issue: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=23891
Thanks,
Joined: 17-Aug-2003
yep, think that's it indeed. For the record, this 'design flaw' is still open (so it's not fixed in 5.1) as it's not that big of a deal when using the methods as intended (namely on the DB), as it won't happen there, but we do plan to solve it at some point. The linked thread has a workaround though.
Joined: 04-Dec-2014
This document projection is quite frustrating to use
I use ProjectToOrganization() on IQueryable and it still breaks on null at OrganizationEmployeeDemographics.
public async Task<IQuerySetPaging<Organization>> GetToModel(OrganizationFilter filter, OrganizationPrefetch prefetch, int page, int pageSize)
{
return await Query.GetAsync(async meta =>
{
var query = from x in meta.Organization
select x;
query = filter.Filter(query);
var total = await query.CountAsync();
var result = await query.WithPath(prefetch.Get()).Take(pageSize).Skip((page - 1) * pageSize).ProjectToOrganization().ToListAsync();
return QuerySet.Paging(result, total).GetPagingInfo(page, pageSize);
});
}
private static System.Linq.Expressions.Expression<Func<Inspection.Data.EntityClasses.OrganizationEntity, Inspection.ViewModel.DtoClasses.Organization>> CreateProjectionFunc()
{
return p__0 => new Inspection.ViewModel.DtoClasses.Organization()
{
AdditionalInfo = p__0.AdditionalInfo,
Address = p__0.Address,
AddressArea = p__0.AddressArea,
AddressGpsLat = p__0.AddressGpsLat,
AddressGpsLng = p__0.AddressGpsLng,
DateCreated = p__0.DateCreated,
Id = p__0.Id,
InsuranceNumber = p__0.InsuranceNumber,
IsActive = p__0.IsActive,
LastModified = p__0.LastModified,
LicenseExpirationDate = p__0.LicenseExpirationDate,
LicenseIssueDate = p__0.LicenseIssueDate,
LicenseNumber = p__0.LicenseNumber,
Name = p__0.Name,
Office = new Inspection.ViewModel.DtoClasses.OrganizationTypes.Office()
{
AddressCityId = p__0.Office.AddressCityId,
DateCreated = p__0.Office.DateCreated,
DepartmentId = p__0.Office.DepartmentId,
Id = p__0.Office.Id,
IsActive = p__0.Office.IsActive,
LastModified = p__0.Office.LastModified,
LastModifiedByUserId = p__0.Office.LastModifiedByUserId,
Name = p__0.Office.Name,
OfficeTypeId = p__0.Office.OfficeTypeId,
ParentOfficeId = p__0.Office.ParentOfficeId,
},
OfficeId = p__0.OfficeId,
OrganizationBusinessActivity = new Inspection.ViewModel.DtoClasses.OrganizationTypes.OrganizationBusinessActivity()
{
ArabicName = p__0.OrganizationBusinessActivity.ArabicName,
EnglishName = p__0.OrganizationBusinessActivity.EnglishName,
Id = p__0.OrganizationBusinessActivity.Id,
},
OrganizationContacts = p__0.OrganizationContacts.Select(p__1 => new Inspection.ViewModel.DtoClasses.OrganizationTypes.OrganizationContact()
{
CreatedByUserId = p__1.CreatedByUserId,
DateCreated = p__1.DateCreated,
Id = p__1.Id,
OrganizationId = p__1.OrganizationId,
Person = new Inspection.ViewModel.DtoClasses.OrganizationTypes.OrganizationContactTypes.Person()
{
Address = p__1.Person.Address,
AddressCityId = p__1.Person.AddressCityId,
AddressPostCode = p__1.Person.AddressPostCode,
BirthDate = p__1.Person.BirthDate,
CreatedByUserId = p__1.Person.CreatedByUserId,
DateCreated = p__1.Person.DateCreated,
Email = p__1.Person.Email,
FirstName = p__1.Person.FirstName,
Gender = p__1.Person.Gender,
Id = p__1.Person.Id,
IsActive = p__1.Person.IsActive,
LastName = p__1.Person.LastName,
MobilePhone = p__1.Person.MobilePhone,
ProfilePicturePath = p__1.Person.ProfilePicturePath,
},
PersonId = p__1.PersonId,
Position = new Inspection.ViewModel.DtoClasses.OrganizationTypes.OrganizationContactTypes.Position()
{
ArabicName = p__1.Position.ArabicName,
EnglishName = p__1.Position.EnglishName,
Id = p__1.Position.Id,
IsMinistry = p__1.Position.IsMinistry,
IsOrganization = p__1.Position.IsOrganization,
},
PositionId = p__1.PositionId,
}).ToList(),
OrganizationEmployeeDemographics = p__0.OrganizationEmployeeDemographics.Select(p__1 => new Inspection.ViewModel.DtoClasses.OrganizationTypes.OrganizationEmployeeDemographic()
{
Count = p__1.Count,
CreatedByUserId = p__1.CreatedByUserId,
DateCreated = p__1.DateCreated,
EmployeeDemographicTypeId = p__1.EmployeeDemographicTypeId,
Id = p__1.Id,
LastModified = p__1.LastModified,
LastModifiedByUserId = p__1.LastModifiedByUserId,
OrganizationId = p__1.OrganizationId,
}).ToList(),
OrganizationSector = new Inspection.ViewModel.DtoClasses.OrganizationTypes.OrganizationSector()
{
ArabicName = p__0.OrganizationSector.ArabicName,
EnglishName = p__0.OrganizationSector.EnglishName,
Id = p__0.OrganizationSector.Id,
IsActive = p__0.OrganizationSector.IsActive,
},
TotalNumberOfEmployees = p__0.TotalNumberOfEmployees,
Website = p__0.Website,
};
}
Filename | File size | Added on | Approval |
---|---|---|---|
query-problems.png | 16,723 | 30-Dec-2016 12:53.29 | Approved |
Joined: 17-Aug-2003
(please next time copy exceptions as text, not as pictures).
the error suggests it crashes on the Count() method, not on the dto projection method. No idea what the filter is, but it looks like that one doesn't match the queryable, but there are no specifics in your post so can't say for sure.
Stacktrace will show where it exactly goes wrong.