c# - Unable to read system views in Entity Framework -


i trying execute following query

  select object_id    sys.tables    sys.tables.name = 'projects' 

as

int n = context.database.sqlquery<int>(       "select object_id sys.tables sys.tables.name = 'projects'")       .firstordefault(); 

i n 0

if use sqlconnection , query using sqlcommand correct results. why dbcontext.database.connection not let me execute plain sql query?

for simplicity have removed sqlparameter, aware code not sql injection safe.

there no problem system views, entity framework cannot read value types in sqlquery. had change it,

public class singlevalue<t>{     public t value {get;set;} }  int n = context.database.sqlquery<singlevalue<int>>(   "select object_id value sys.tables sys.tables.name = 'projects'")   .tolist().select(x=>x.value).firstordefault(); 

Comments

Popular posts from this blog

php - Extract Text from HTTP referer -

Receive udp packets in android gstreamer -

authentication - ASP.NET Core 1.0. Bearer Token, cannot access custom claims -