I'm calling sprocs from asp.net core using Entity framework core in an MVC/Razor/WebAPI app. Newer dev so apologies if this is nube. I have read everything I can find on sprocs from EF...
Issue: When I setup my app to call a sproc, EF Core updates my DB (via the next Migration I run) to create an empty table based on the model I created to retrieve output from the sproc.
Example: I have a a sproc that returns two columns
SELECT customerID, customerName from MyTable
I add a simple POCO MyModel using [Keyless] directive
namespace MyApp.Models
{
[Keyless]
public class MyModel
{
public int customerID { get; set; }
public string customerName { get; set; }
}
}
I then register the class in my ApplicationDBContext
public virtual DbSet<MyModel> MyModel { get; set; }
I can now call the sproc from my pages using:
public List<MyModel> CustomerList { get; set; }
and
CustomerList = _context.MySproc
.FromSqlRaw($"MySproc")
.ToList();
When I next run a migration, EF adds migration code to create a table based on my model, which I don't believe I need.
migrationBuilder.CreateTable(
name: "VerifyEmailAndStripeCustomerID",
columns: table => new
{
customerID = table.Column<int>(type: "int", nullable: false),
customerName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true)
},
How can I call my sprocs without this table creation behavior?