zzzprojects / EntityFramework-Plus

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
https://entityframework-plus.net/
MIT License
2.25k stars 318 forks source link

Cannot use a subclass of the DevArt OracleConnection #637

Open citypermit opened 3 years ago

citypermit commented 3 years ago

Description

We derived from the DevArt OracleConnection to add some functionality. However EF+ batch functions without a table name specified, are throwing exceptions. That is because the EntityContainerEntitySet.GetDestinationTableName function only investigates the top-level type of the DbConnection object. Is it possible to make it more flexible to investigate the type hierarchy? Something like: `public static class Program { public static void Main() { using (var connection = new DerivedOracleConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString)) { if (GetTypeHierarchy(connection).Any(type => type.Name == "OracleConnection")) { // ... } } }

private static IEnumerable<Type> GetTypeHierarchy(object o)
{
    var type = o?.GetType();
    while (type != null)
    {
        yield return type;
        type = type.BaseType;
    }
}

}

public class DerivedOracleConnection : Devart.Data.Oracle.OracleConnection { public DerivedOracleConnection(string connectionString) : base(connectionString) { } }`

Exception

Exception message:
System.Exception
  HResult=0x80131500
  Message=Oops! The destination table name could not be found. That typically happens for an unsupported provider. If you use a custom connection, contact us to learn how to set it up within our library. Please report the issue to our support team : info@zzzprojects.com
  Source=Z.EntityFramework.Extensions
  StackTrace:
   at Z.EntityFramework.Extensions.Core.SchemaObjectModel.EntityContainerEntitySet.GetDestinationTableName(DbContext context, String databaseName, String schemaName)
   at `1.()
   at `1.Execute(IQueryable`1 query, String databaseName, String schemaName, String tableName, Expression`1 selectFieldsExpression, Type tableType)
   at DbContextExtensions.[](IQueryable`1 , String , String , String , Expression`1 , Type )
   at DbContextExtensions.InsertFromQuery[TEntity](IQueryable`1 query, Expression`1 selectFieldsExpression)
   at TestConsoleApplication.Program.Main() in C:\local\TestConsoleApplication\TestConsoleApplication\Program.cs:line 12

Fiddle or Project

Included my test project. The connection string is of course changed. TestConsoleApplication.zip

Further technical details

JonathanMagnan commented 3 years ago

Hello @citypermit ,

Thank you for reporting.

We will look at it

Best Regards,

Jon


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function