I have model generated by ADO Entity Data Model like:
public partial class Category
{
public Category()
{
}
public int CategoryId { get; set; }
public string Name { get; set; }
}
now I have added one property
public partial class Category
{
public int EventsCount { get; set; }
}
Now I am trying to map by: //this is working Query
List<Category> retVal = db.Database.SqlQuery<Category>(
//retVal = db.Categories.SqlQuery(
@"SELECT c2.CategoryId,c2.Name,c1.EventsCount AS EventsCount FROM (
SELECT c.CategoryId, COUNT(c.CategoryId) AS EventsCount FROM Category c
JOIN EventCategory ec ON ec.CategoryId = c.CategoryId
JOIN (SELECT * FROM EVENT WHERE EventDateTime > DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))) e ON e.EventId = ec.EventId
WHERE c.ImportedFrom IS NULL
GROUP BY c.CategoryId) c1
join Category c2 ON c1.CategoryId = c2.CategoryId").ToList();
Actual Data I get executing raw sql on Management Studio
but EventCounts
is always 0
with Entity Framework mapping ,
but If I map model with different Model having EventsCount
, then it is mapped.
like:
public partial class Category
{
public Category()
{
}
public int CategoryId { get; set; }
public string Name { get; set; }
public int EventsCount { get; set; }
}
now there are mapped all columns,, Any idea here, why Entity framework in not mapping partial model?