You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using .net core 3.1 application in which i have referenced entity framework core 3.1.8 and using various tables via model first approach. (db is mysql)
Now I need some custom join query where i have to run manual queries.
I am trying code from #1862
public static class SqlQueryExtensions
{
public static IList<T> SqlQuery<T>(this DbContext db, string sql, params object[] parameters) where T : class
{
using (var db2 = new ContextForQueryType<T>(db.Database.GetDbConnection()))
{
return db2.Set<T>().FromSqlRaw(sql, parameters).ToList();
}
}
private class ContextForQueryType<T> : DbContext where T : class
{
private readonly DbConnection connection;
public ContextForQueryType(DbConnection connection)
{
this.connection = connection;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(connection, options => options.EnableRetryOnFailure());
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<T>().HasNoKey();
base.OnModelCreating(modelBuilder);
}
}
}
but it is not compiling.
Please suggest is it related to nuget package difference or what?
The text was updated successfully, but these errors were encountered:
You probably need to change this line to use the MySQL provider (I am in the blind here, since you are not sharing any information about the build errors):
I am using .net core 3.1 application in which i have referenced entity framework core 3.1.8 and using various tables via model first approach. (db is mysql)
Now I need some custom join query where i have to run manual queries.
I am trying code from #1862
but it is not compiling.
Please suggest is it related to nuget package difference or what?
The text was updated successfully, but these errors were encountered: