I have a view in database with several columns. I am trying this query
public class TestEntity
{
public string ref { get; set; }
public string Name { get; set; }
public string Batch { get; set; }
}
var res = dbContext.Database.SqlQuery<TestEntity>("Select * from dbo.MyView").ToList();
but this returns list of objects with only null values and no data. However, when I try to retrieve single column like this it works
var res = dbContext.Database.SqlQuery<string>("Select Name from dbo.MyView").ToList();
I have noticed that the problem is with the TestEntity because when I use string instead of TestEntity it works. Any suggestion what am I doing wrong here?
NULLrecords ->WHERE Col1 IS NOT NULL AND Col2 IS NOT NULL..