I have an entity that works fine, but then I have a requirement to stick to the extra property that comes from another table. I have no way to pretend, so I just want to add the [NotMapped] field and then use Context.Database.SqlQuery to execute my user statement and return all normal fields and this new field.
In other words, something like this:
public class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
[NotMapped]
public string CustomerName { get; set; }
}
public List<Employee> GetEmployees()
{
using (MyContext context = new MyContext())
{
return context.Database.SqlQuery<Employee>("select E.EmployeeId, E.EmployeeName, C.CustomerName from Employee E left join Customer C on E.CustomerId = C.CustomerId").ToList();
}
}
Yes, yes, not the best example, but the easiest way to get the point. From everything I read, SqlQuery should ignore the attribute, so it should work, but my CustomerName always returns null (I ran SQL in Management Studio, it matters there, but not after EF deserializes into my objects).
, ? ? EF , ?
-shnar