SqlParameter已包含在另一个SqlParameterCollection-EF中

时间:2016-07-19 16:37:44

标签: entity-framework rawsql

我使用EF的DBContext来执行存储过程。这是函数

public IEnumerable<Customer> GetCustomerInfoforSearch(string bfcSalesRecipientId, string companyName, string contactName, string phoneNumber, string emailId, string ageroProviderNumber)
{
    var bfcSalesRecipientIdParam = new SqlParameter("@saleRecipientId", bfcSalesRecipientId);
    var companyNameParam = new SqlParameter("@companyName", companyName);
    var contactNameParam = new SqlParameter("@contactName", contactName);
    var phoneNumberParam = new SqlParameter("@phoneNumber", phoneNumber);
    var emailIdParam = new SqlParameter("@emailId", emailId);
    var ageroProviderNumParam = new SqlParameter("@ageroProviderNumber", ageroProviderNumber);

    object[] sqlParams = new object[] { bfcSalesRecipientIdParam, companyNameParam, contactNameParam, phoneNumberParam, emailIdParam, ageroProviderNumParam };
    var result = Context.Database.SqlQuery<Customer>("dbo.Customer_SearchContact {0}, {1}, {2}, {3}, {4}, {5}", bfcSalesRecipientIdParam, companyNameParam, contactNameParam, phoneNumberParam, emailIdParam, ageroProviderNumParam).ToList();
   return result;
}

但是这会引发以下错误:

  

SqlParameter已包含在另一个SqlParameterCollection

0 个答案:

没有答案