I'm having a procedure which simply returns data from multiple tables. I'm trying to execute this procedure from EF as follows
await _context.Database.SqlQuery<TEntity>(command).ToListAsync();
Firstly, I have created a model class with property names to match the columns returned by the SP. Removed some properties for simplification,
public partial class Inventory
{
public string? location { get; set; }
public string? Warehouse { get; set; }
public string? Company { get; set; }
public string? Item { get; set; }
}
secondly, Added DbSet property to the context class
public virtual DbSet<Inventory> Inventorys { get; set; }
Then, I'm trying to call MapToStoredProcedures on entity Inventory.
modelBuilder.Entity<Inventory>().MapToStoredProcedures();
But, MapToStoredProcedures() is not recognized. I've verified that EF 7 packages are referenced by the project. What Am I missing here?
CodePudding user response:
I followed the steps in https://erikej.github.io/efcore/2020/08/03/ef-core-call-stored-procedures-out-parameters.html and was able to get it working.