Friday, July 15, 2016

How to pass parameters to the DbContext.Database.ExecuteSqlCommand method?

Depending on your underlying database provider, you can use either of the following.
Database.ExecuteSqlCommand(
    "exec SetElementFrequency {0}, {1}",
    elementType, frequency); 
or
Database.ExecuteSqlCommand("exec SetElementFrequency ?, ?", elementType, frequency); 
You may also specify elementType and frequency as DbParameter-based objects to provide your own names via the ParameterName property.

No comments:

Post a Comment