GithubHelp home page GithubHelp logo

Comments (6)

voronov-maxim avatar voronov-maxim commented on June 8, 2024

You can show example code in TypeResolve method?

from odatatoentity.

dshalkhakov avatar dshalkhakov commented on June 8, 2024

Somewhere early in program startup, and done exactly once:

System.AppDomain.CurrentDomain.TypeResolve += HandleTypeResolve

Then the HandleTypeResolve will be called when DynamicTypeDefinitionManager looks for a db context type using Type.GetType and doesn't find it.

And in HandleTypeResolve we'll look up the type in cache, generate it if needed, and then return it, like so (in pseudocode):

private System.Reflection.Assembly HandleTypeResolve(object sender, System.ResolveEventArgs args)
{
    if (_dynamicTypeService.IsDynamicContext(args.Name))
    {
        return _dynamicTypeService.GetOrCreateDynamicContext(args.Name);
    }
    return null;
}

But the problem remains that the DynamicTypeDefinitionManager [1] is implemented in such a way that new types need to be generated over and over again and never be disposed of/re-used.

How about introducing

  1. dynamic type generation instead of [2][3]
  2. LRU cache for said DynamicTypeDefinitionManager?

[1]


[2] https://github.com/voronov-maxim/OdataToEntity/blob/master/source/OdataToEntity.EfCore.DynamicDataContext/Types/DynamicDbContexts.cs
[3] https://github.com/voronov-maxim/OdataToEntity/blob/master/source/OdataToEntity.EfCore.DynamicDataContext/Types/DynamicTypes.cs

EDIT: formatting

from odatatoentity.

voronov-maxim avatar voronov-maxim commented on June 8, 2024

Hi @dshalkhakov!

IEdmModel edmModel = DynamicMiddlewareHelper.CreateEdmModel(providerSchema, informationSchemaSettings);

must be

IEdmModel edmModel = DynamicMiddlewareHelper.CreateEdmModelViaEmit(providerSchema, informationSchemaSettings);

from odatatoentity.

dshalkhakov avatar dshalkhakov commented on June 8, 2024

Hi @voronov-maxim. I've looked into that method and the commit it appears in. It looks like it'd do the trick.
I wonder why it hasn't been released yet. Any reasons?

from odatatoentity.

dshalkhakov avatar dshalkhakov commented on June 8, 2024

I've also looked into the current source [1][2] and it seems DynamicDbContexts are still not generated dynamically. A custom EmitDynamicTypeDefinitionManagerFactory might rectify that.

[1]

return EmitDynamicTypeDefinitionManager.Create(metadataProvider, CreateDynamicDbContextType());

[2]

from odatatoentity.

voronov-maxim avatar voronov-maxim commented on June 8, 2024

Release nuget 2.6.1

To create a DynamicDbContext, an emit constructor is required. I do not see the need for this since only one context is used by default. Several contexts are used for xunit tests.

from odatatoentity.

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.