Getting a raw Entity Framework query to evaluate attributes

I use EF4 code first. Thus, my model classes combine common properties, some virtual properties (for lazy loading data from other tables) and some properties that are bound to attributes [NotMapped], so that they are ignored by EF.

Sometimes I like to use a raw query: c.Database.SqlQuery<T>("select ...")use EF as a string match.

In Intellitrace, I noticed that these queries throw a lot of thrown and caught exceptions for "IndexOutOfRange". After some searching, exceptions are used for the virtual and [NotMapped] properties of the model object. I do not want to create a new data model class or a parent class with only table properties in it; Is there any configuration step that I skipped to tell the line builder in the raw query slider to pay attention to the same annotations that the rest of EF uses? Perhaps they fixed it in EF5?

+5
source share
1 answer

dbContext.Database.SqlQuery, EF . . dbSet.SqlQuery. , .

+1

All Articles