I’m trying to query abstract entity using SqlQuery() method (code first).
public abstract class UserComment
{
... [internals]
}
public class BlogComment : UserComment
{
... [internals]
}
var result = Context.Database.SqlQuery<UserComment>(
@"select * from [UserComments] where ... [internals]",
new SqlParameter("user_id", user.Id));
This gives me error:
System.ArgumentNullException: Value cannot be null. Parameter name: constructor
If I change abstract type to concrete..
Context.Database.SqlQuery<BlogComment>
…everything works fine.
Is it possible to query abstract class using raw queries?
I didn’t try it but I expect the answer is no. You cannot create instance of abstract class and that is exactly what EF is trying to do when materializing result set of the raw query.