I am needing to convert from EF6 to .net core 2.2.x and I have been searching but I don't see how to convert some of this code from possibly EDMX
Example of what I need to convert
public virtual ObjectResult<string> GetTransData(string iN_MEM_ID)
{
var iN_MEM_IDParameter = iN_MEM_ID != null ?
new ObjectParameter("IN_MEM_ID", iN_MEM_ID) :
new ObjectParameter("IN_MEM_ID", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("GetTransData", iN_MEM_IDParameter);
}
Typically I will create a file of dbcontext like this
public Clinical_CaseTrakker_Context(DbContextOptions<Clinical_CaseTrakker_Context> options) : base(options)
{ }
Then I do dbset like
public DbSet<USP_Get_SAI> USP_Get_SAIs { get; set; }
But this whole ObjectResult<T>
I never worked with
Normally I will just call a stored proc like this
List<OfflineMember> offLine = await _CaseTrakker_Context.OfflineMembers.FromSql("EXECUTE CT.usp_Get_SAI_Offline_Members {0}", userId).ToListAsync();
Could you use FromSqlRaw?
var blogs = context.Blogs
.FromSqlRaw("EXECUTE dbo.GetMostPopularBlogs")
.ToList();
FromSqlRaw allows you to use named parameters in the SQL query string, which is useful when a stored procedure has optional parameters:
var user = new SqlParameter("user", "johndoe"); var blogs = context.Blogs .FromSqlRaw("EXECUTE dbo.GetMostPopularBlogsForUser @filterByUser=@user", user) .ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With