Gay*_*yan 3 entity-framework repository-pattern
我正在尝试将存储库模式用于我的vsto项目.
如何使用存储库模式执行存储过程?我正在使用实体框架.代码示例的任何链接都非常有用
添加到您的通用存储库
public IEnumerable<T> ExecWithStoreProcedure(string query, params object[] parameters)
{
return _context.Database.SqlQuery<T>(query, parameters);
}
Run Code Online (Sandbox Code Playgroud)
然后你就可以用任何unitofwork/repository来调用它
IEnumerable<Products> products =
_unitOfWork.ProductRepository.ExecWithStoreProcedure(
"spGetProducts @bigCategoryId",
new SqlParameter("bigCategoryId", SqlDbType.BigInt) { Value = categoryId }
);
Run Code Online (Sandbox Code Playgroud)