Why does my raw query to count rows always returns -1?

后端 未结 2 341
醉话见心
醉话见心 2021-01-20 15:38

I\'m trying to check if table exists, but not working correctly.

For some reason, count always returns -1. I already have a table in the database. It should return

2条回答
  •  爱一瞬间的悲伤
    2021-01-20 16:10

    ExecuteStoreQuery Directly Execute Commands Against the Data Source.

    int result = entity.ExecuteStoreQuery(@"
    IF EXISTS (SELECT * FROM sys.tables WHERE name = 'TableName') 
        SELECT 1
    ELSE
        SELECT 0
    ").SingleOrDefault();
    

    See answer here.

提交回复
热议问题