execute stored procedure in entity Framework Core without expecting map to dbset

.net-core c# entity-framework-core stored-procedures


I'm working on the Entity Framework core for.NET CORE. I need to use a.NET class to run a stored procedure. Although I have dataView, which is the ultimate exception, my stored method accepts a lot of "Context" parameters, and I'm not sure how to handle this.

I wonder whether I can replace context with my dataView. dataModel class, as it is used today (Context.Claims.FromSql)


public class ClaimDataView
    public Guid ClaimId { get; set; }
    public int IdNum { get; set; }
    public string Value { get; set; }
    public DateTime ExpirationDate { get; set; }
    public ClaimAttributionActions Action { get; set; }
    public bool ActiveStateForRole { get; set; }


call to a stored-Procedure

public Guid UserId { get; set; }
public Guid ClientId { get; set; }
public Guid ConsultationId { get; set; }

  var userParam = new SqlParameter("@UserVal", UserId);
  var clientParam = new SqlParameter("@ClientVal", ConsultationId);
  var consultationParam = new SqlParameter("@ConsultationVal", ConsultationId);

 //**************need help in following line
  var query = Context.Claims.FromSql("EXECUTE dbo.ListUserClaims @userId=@UserVal, @clientId=@ClientVal, @consultationId=@ConsultationVal"
            , userParam, clientParam, consultationParam);

new revision

class moduleContext

  protected override void OnModelCreating(ModelBuilder modelBuilder)
       //other models....

Executing a stored procedure from

 var query = Context.Query<UserDataView>().FromSql("EXECUTE dbo.ListUserClaims @userId=@UserVal, @clientId=@ClientVal, @consultationId=@ConsultationVal"
            , userParam, clientParam, consultationParam);


System.InvalidOperationException: Cannot create a DbSet for 'UserDataView' because this type is not included in the model for the context.
 at Microsoft.EntityFrameworkCore.Internal.InternalDbQuery`1.get_EntityType()
8/24/2018 12:24:09 PM

Accepted Answer

4/2/2020 12:35:12 PM

Popular Answer


Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow