Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Working with EF Core

$
0
0

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


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>