1

I have a stored procedure that returns a dataset without any primary key. The documentation states that you should call a stored procedure on the DbSet like:

var blogs = context.Blogs
    .FromSqlRaw("SELECT * FROM dbo.Blogs")
    .ToList();

However I do not have a DB set. I can do something like:

await this.Database.ExecuteSqlRawAsync("[xxx].[VF_Set_PrimaryXXX] @BankDataId",param1);

But this does not return data. So how do I call a stored procedure and return my own custom model in a list?

Thomas Segato
  • 4,567
  • 11
  • 55
  • 104
  • EF Core requires the creation of a model and a DbSet. You will need to create a db set of an keyless entity type: https://stackoverflow.com/questions/58996385/is-a-dbset-required-to-run-a-stored-procedure and https://learn.microsoft.com/en-us/ef/core/modeling/keyless-entity-types?tabs=data-annotations – Marc May 30 '20 at 19:19
  • I dont think that is true. I added an answer where you can see how I solved it without dbset. – Thomas Segato Jun 01 '20 at 07:10

1 Answers1

1

I soved it like this:

using (var db = new DB(_connStr))
{
    return db.Set<TeamMemberIteration>().FromSqlRaw("GetTeamMembersViewFromCurrentIteration").ToList();

}
Thomas Segato
  • 4,567
  • 11
  • 55
  • 104
  • Hi! To complete your example ypur have to add `TeamMemberIteration` entity into the s `YourContext : DbContext` class and have `Key` attribute for `Primary Key` of it. – NoWar Nov 03 '21 at 02:55