I have a model of type DbQuery
in my context for executing a stored procedure in it.
public class DynamicClass
{
public int ItemId { get; set; }
[NotMapped]
public string Title { get; set; }
[NotMapped]
public string TitleArabic { get; set; }
public int? SeasonNumber { get; set; }
}
Query:
SELECT ItemId, Title, TitleArabic, SeasonNumber
FROM dynamicclass
List<DynamicClass> Result = context.DynamicClass.FromSql("SELECT ItemId,Title,TitleArabic,SeasonNumber From dynamicclass").ToList();
The query is working fine but the NotMapped
fields are not getting values while executing the query.
My query may or may not contain Title
and TitleArabic
and that is why I have assigned NotMapped
annotation to these fields.
If I removed all the NotMapped
annotations and query results doesn't contain all the columns I have specified in the model, then I get an error
The required column 'Title' was not present in the results of a 'FromSql' operation
How can I solve this or is there any better idea?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…