-1

So far I was calling my stored procedures like :

using (Entities ent = new Entities())
{
    test = atlEnt.Database.SqlQuery<GetCarriersById_Result>("CarriersById @CarID, @FacilityID",
    new SqlParameter("@CarID", id)
    , new SqlParameter("@FacilityID", facilityId)).FirstOrDefault();
}

How can I add the parameters with a separate statements?

Lio Programista
  • 163
  • 2
  • 11
  • Possible duplicate of [How to call Stored Procedure in Entity Framework 6 (Code-First)?](https://stackoverflow.com/questions/20901419/how-to-call-stored-procedure-in-entity-framework-6-code-first) – CodeNotFound May 31 '18 at 12:50
  • It's not clear what you mean by *with a separate statements*, why do you care if it's separate statements? – DavidG May 31 '18 at 12:52

1 Answers1

1

You can specify parameters as to have this in separate line

List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("@CarID", id));
parameters.Add(new SqlParameter("@FacilityID", facilityId));

And invoke the query as

test = atlEnt.Database.SqlQuery<GetCarriersById_Result>("CarriersById @CarID, @FacilityID", parameters.ToArray());

You can check the documentation of SqlQuery method here. The SqlQuery method allows to specify parameters as params.

user1672994
  • 10,509
  • 1
  • 19
  • 32