Last post Oct 03, 2014 05:52 PM by ivan.petrovic
Sep 18, 2014 08:04 PM|ivan.petrovic|LINK
I am trying to retrieve list of EmployeeDTO from DB which are stored in Employee table. Every employee can has one or more specialty. Specialty are stored in OrganizationSpecialtyType. Employee and OrganizationSpecialtyType are related with "many to many"
via EmployeeSpecialty table.
var q = _context.Employee.Where(p => employeeEMIIDs.Contains(p.EmployeeID))
.Select(p => new EmployeeDTO
EmployeeID = p.EmployeeID,
GenderTypeID = p.GenderTypeID,
FirstName = p.FirstName,
LastName = p.LastName,
Name = p.Name,
MiddleName = p.MiddleName,
DOB = p.DOB,
Suffix = p.Suffix,
Title = p.Title,
Sepcialty = p.EmployeeSpecialty
.ToDictionary(d => d.OrganizationSpecialtyType.SpecialtyTypeID, d => d.OrganizationSpecialtyType.Name)
In EmployeeDTO class property specialty is type public Dictionary.
If I execute this query, everything works normaly:
var spec = _context.Employee.Where(p => p.EmployeeID == -9070).FirstOrDefault().EmployeeSpecialty.ToDictionary(d => d.OrganizationSpecialtyType.SpecialtyTypeID, d => d.OrganizationSpecialtyType.Name);
How I can solve my first query to obtain EmployeeDTO with specialties?
Sep 21, 2014 10:08 PM|Kevin Shen - MSFT|LINK
If you don't mind,please share your project which can reproduce your problem on onedrive(https://onedrive.live.com/?gologin=1&mkt=en-US) for me to test.
Sep 22, 2014 06:27 PM|ivan.petrovic|LINK
Sorry Kevin, but I can't share project. This is a small piece (only sample) of project. In any case I avoid dictionary and use object field in DTO class. I populate this field with anonymus type instead Dictionary. Because I didn't found what cause exception.
Maybe it is EF bug.
Sep 29, 2014 05:06 AM|Kevin Shen - MSFT|LINK
Have you solved your issue?If do ,please share your solution and mark the reply.
If not ,please post your code which can reproduce your issue (remove your personal information), so that we can test it in my side.
Oct 03, 2014 05:52 PM|ivan.petrovic|LINK
I didn't solve my problem because it isn't possible in way which I want.
You can easy reproduce issue. Just put .ToDictionary() into Select statement.