1

I have the following function in my SQL Server:

getMaxSL(paramter)

which will return a string value.

I have tried to call and execute this function from the Entity Framework in the following ways but did not work for me, instead it's returning the sql query itself.

var styleCode = (_dbContext as IObjectContextAdapter).ObjectContext.CreateQuery<string>("Select dbo.getMaxSL(500)");

and

var styleCode = _dbContext.Database.SqlQuery<string>("Select dbo.getMaxSL(500)");

Would anyone tell me what are the best possible ways to call and execute a SQL Server function in Entity Framework??

1 Answer 1

1

Finally I myself found the solution as expected:

The codes should be as follows:

var styleCodeID = (_dbContext as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery<string>("Select dbo.getMaxSL(500)").FirstOrDefault();

and

var styleCode = _dbContext.Database.SqlQuery<string>("Select dbo.getMaxSL(500)").FirstOrDefault();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.