There is a stored proc as below with two selects. And i have to pass only one parameter (i.e Name ) to one SELECT through SQLQuery. How could i achieve that?
Stored procedure :
"USE [CustomerDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetCustomers] @Name nvarchar(max), @ZipCode int
AS
SELECT [Id], [Name],[ZipCode] FROM [dbo].[Customers] WHERE [Name] LIKE (@Name);
SELECT [Id], [Name],[ZipCode] FROM [dbo].[Customers] WHERE [ZipCode] = @ZipCode;
GO"
public List GetCustomersByName(string name, int zipcode)
{
List ilst = new List();
using (CustomerContext cx = new CustomerContext())
{
var result = cx.Database.SqlQuery("GetCustomers. @Name", new SqlParameter("@Name", name));
foreach (Customer c in result)
{
Customer cust = new Customer();
cust.Name = c.Name;
cust.Zipcode = c.Zipcode;
ilst.Add(cust);
Console.WriteLine(cust.Name, cust.Zipcode);
}
}
return ilst;
}

Bryian TanPosted Jul 8, 2018, 10:57 PM
Naresh SethPosted Jul 11, 2018, 10:37 AM
Jignesh KumarPosted Jul 11, 2018, 9:43 AM
Naresh SethPosted Jul 11, 2018, 9:16 AM
Nitin SontakkePosted Jul 11, 2018, 1:50 AM
Jignesh KumarPosted Jul 11, 2018, 1:30 AM
Nitin SontakkePosted Jul 10, 2018, 3:38 AM
Packiaraj SanthiyaguPosted Jul 9, 2018, 2:43 AM
Naresh SethPosted Jul 8, 2018, 1:59 PM
Jignesh KumarPosted Jul 8, 2018, 1:19 AM
Faisal PathanPosted Jul 6, 2018, 11:27 PM