Git Product home page Git Product logo

Comments (5)

amccorma avatar amccorma commented on June 29, 2024 1

i got it it working with adding an interceptor. I test it and it works. Ef Core 7.0

In EfContext class:

DbInterception.Add(new Org.Infrastructure.Interceptor.MyCommandInterceptor());

public class MyCommandInterceptor : Z.EntityFramework.Extensions.IDbInterceptor
{
    public void OnCompleted()
    {       
    }

    public void OnError(Exception error)
    {
        
    }

    public void OnNext(DiagnosticListener value)
    {
        value.Subscribe(new My2());
    }
}
public class My2 : System.IObserver<KeyValuePair<string, object?>>
{
    public void OnCompleted()
    {
    }

    public void OnError(Exception error)
    {
    }

    public void OnNext(KeyValuePair<string, object?> value)
    {
        if (value.Key == "Microsoft.Data.SqlClient.WriteCommandBefore" ||
            value.Key == "Microsoft.EntityFrameworkCore.Database.Command.CommandInitialized")
        {
            var obj = ToDynamic(value.Value);
            var command = obj.Command as Microsoft.Data.SqlClient.SqlCommand;
            if (command != null)
            {
                command.CommandText = command.CommandText
                        .Replace("[X.X1]", "[X.[X1]")
                        .Replace("[X3.X4].", "[X3].[X4].");
            }
        }
    }

from entityframework-extensions.

JonathanMagnan avatar JonathanMagnan commented on June 29, 2024

Hello @amccorma ,

You are right; our library doesn't use a listener or interceptor.

You should be able to change the table name within our library with the PostConfiguration event.

Here is an example:

// globally
Z.EntityFramework.Extensions.EntityFrameworkManager.BulkOperationBuilder = builder => builder.PostConfiguration = configuration =>
{
	configuration.DestinationTableName = configuration.DestinationTableName
             .Replace("[X.Shared].", "[X].[Shared].")
             .Replace("[X1.Common].", "[X1].[Common].")
             .Replace("[X2.Primary]","[X2].[Primary]")
};

// or by operation (which override the globally for the specific option)
context.BulkSaveChanges(options => options.PostConfiguration = configuration =>
{
	configuration.DestinationTableName = configuration.DestinationTableName
             .Replace("[X.Shared].", "[X].[Shared].")
             .Replace("[X1.Common].", "[X1].[Common].")
             .Replace("[X2.Primary]","[X2].[Primary]")
});

It might be slightly different depending of what exactly you want to do, but I believe you will be able to find out how to make it work correctly with this information.

Let me know if that solves your current problem or if you need more help.

Best Regards,

Jon

from entityframework-extensions.

amccorma avatar amccorma commented on June 29, 2024

That worked ok for the Framework.Extensions.

Do you have a similar method for the Z.EntityFramework.Plus framework = the future, cache functions. I checked and can not find anything. the code above does nothing for the Plus framework. Thanks

from entityframework-extensions.

JonathanMagnan avatar JonathanMagnan commented on June 29, 2024

Hello @amccorma ,

Unfortunately, no, EF Plus (for EF Core) still doesn't support interceptors.

Best Regards,

Jon

from entityframework-extensions.

JonathanMagnan avatar JonathanMagnan commented on June 29, 2024

Indeed, I was wrong,

It makes sense that it works with the Query Cache features in EF Core.

I'm surprised that you were able to make it work for Query Future. Thank you for sharing your solution. I tried it, and it worked, so we will surely look more deeply into it.

Best Regards,

Jon

from entityframework-extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.