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 TanRank #396 · 6.3K reputationPosted Jul 8, 2018, 6:57 PM EDT
Faisal PathanRank #291 · 8.6K reputationPosted Jul 6, 2018, 7:27 PM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Jul 7, 2018, 9:19 PM EDT
Naresh Seth76 reputationPosted Jul 8, 2018, 9:59 AM EDT
Packiaraj SanthiyaguRank #659 · 3.6K reputationPosted Jul 8, 2018, 10:43 PM EDT
Nitin SontakkeRank #264 · 9.6K reputationPosted Jul 9, 2018, 11:38 PM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Jul 10, 2018, 9:30 PM EDT
Nitin SontakkeRank #264 · 9.6K reputationPosted Jul 10, 2018, 9:50 PM EDT
Naresh Seth76 reputationPosted Jul 11, 2018, 5:16 AM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Jul 11, 2018, 5:43 AM EDT
Naresh Seth76 reputationPosted Jul 11, 2018, 6:37 AM EDT