Entity framework returns different result than SSMS

I am facing a rather strange problem

I am trying to run a stored procedure through entity framework to work out counts of different people with date of birth in a specific range

I am running the following code

select count(*), groupId from app_people p
where p.DOB >= '2012-10-02'
and p.DOB <= '2013-10-01
group by groupId

      

The problem I am getting is that the same stored procedure executed via ssms returns 70 whereas the frame structure returns 59

I am inserting the result of the above query into the temp table before updating the existing results table.

Any suggestions as to why this is happening?

Both are passed with the same parameters.

Using the following code to execute the proc structure through the Entity, the procedure was imported from the database and included in the datamodel.

DatabaseContext.TestProcedure(false);

      

+3


source to share


1 answer


This could be a permissions issue as reported in HLGEM . If the connection to SQL Server in the code uses a different login than your SSMS login in SQL Server Management Studio (for example, Windows credentials), you may see different results.

You can use the following TSQL to execute a query from a different security context in SSMS. You can do this to compare the results of the same query for different users.



-- Execute as another user: https://docs.microsoft.com/en-us/sql/t-sql/statements/execute-as-transact-sql
EXECUTE AS USER = 'testuser';

-- TSQL with inconsistent results between code and ssms.
SELECT COUNT(*), groupId FROM app_people;

      

0


source







All Articles