我在SQL Server中有一个名为ParseXML的存储过程。我使用LINQ to SQL实现了仓储模式。我需要在仓储层中调用存储过程。与GetTable方法不同,数据上下文中没有GetStoredProcedure方法。在这种情况下,我们该如何调用存储过程?
Dbml 代码
Dbml 代码
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.ParseXML")]
public ISingleResult<ParseXMLResult> ParseXML([global::System.Data.Linq.Mapping.ParameterAttribute(Name="InputXML", DbType="Xml")] System.Xml.Linq.XElement inputXML)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), inputXML);
return ((ISingleResult<ParseXMLResult>)(result.ReturnValue));
}
仓储层
namespace RepositoryLayer
{
public interface ILijosBankRepository
{
System.Data.Linq.DataContext Context { get; set; }
List<DBML_Project.BankAccount> GetAllAccountsForUser(int userID);
void UpdateBankAccountUsingStoredProcedure();
}
public class LijosSimpleBankRepository : ILijosBankRepository
{
public System.Data.Linq.DataContext Context
{
get;
set;
}
public List<DBML_Project.BankAccount> GetAllAccountsForUser(int userID)
{
IQueryable<DBML_Project.BankAccount> queryResultEntities = Context.GetTable<DBML_Project.BankAccount>().Where(p => p.AccountOwnerID == userID);
return queryResultEntities.ToList();
}
public virtual void UpdateBankAccountUsingStoredProcedure()
{
//Context.GetStroedProcedures();
}
}
}
参考资料: