I want to retrieve a subset of records from a table in an asp.net core app I'm building. Being old school I like to use stored procedures in Sql Server and in this instance the sp I've created uses this statement
Select * from tbl Where Field1=@param1 Or Field2=@param2
@param1 is a string, @param2 is an int
I have used a single parameter sp to return an object in my models successfully in the format:
return context.tbl.FromSqlRaw<entity>("spGetObject {0}", arg).ToList().FirstOrDefault();
but cannot find how to pass multiple parameters. These need to be any type including strings. So if someone can help with this I'd be very grateful. N.B. tbl=the name of the Sql Server table as defined in my AppDbContext class and entity is the name of one of the models in the application, i.e. public DbSet<modelname> tbl { get; set; }
I'd also like to return a list, (so omit the .FirstOrDefault() in the above code, and then traverse to an object in the list and use its values (fields) for processing. I could use a foreach loop but surely there is an easier way of doing this. If there is I'd appreciate help in this too
Best Regards
Andy