GithubHelp home page GithubHelp logo

grinderofl / fluentmodelbuilder Goto Github PK

View Code? Open in Web Editor NEW
20.0 4.0 3.0 1.93 MB

Convention based automated Model Builder for Entity Framework Core

Home Page: http://grinderofl.github.io/FluentModelBuilder

License: MIT License

C# 93.91% PowerShell 4.11% Shell 1.98%

fluentmodelbuilder's Introduction

FluentModelBuilder

Conventional, automated, and fluent way to configure the backing model of your DbContext.

  • Class-based configuration
  • Expression-based configuration
  • Assembly-based discovery
  • Alterations
  • Entity Type Sources
  • Conventions
  • Entity Type Overrides
  • Dependency injection support

All this while keeping in mind developers coming from background of Fluent NHibernate, which this project is greatly inspired by.

Getting started

NuGet:

Build status

Build status

fluentmodelbuilder's People

Contributors

grinderofl avatar

Stargazers

Odenigbo Godfrey avatar Halid Cisse avatar Paul avatar Herman van der Merwe avatar Rafael Brunello avatar Jonathan González avatar balazs HIDEGHETY avatar Coder Monkey avatar Ramon Guerrero avatar  avatar Aleksa Savić avatar Zhen Zhong avatar  avatar Fukuhara.N avatar ganqiyin avatar ahmad molaie avatar Andriy Svyryd avatar  avatar SilverFox avatar Abunet avatar

Watchers

 avatar Abunet avatar James Cloos avatar  avatar

fluentmodelbuilder's Issues

Allow invalidating model depending on criteria

Add a custom ModelCacheKeyFactory which takes an ModelInvalidator as an argument, and creates a new type of ModelCacheKey that contains "version" property. This property is then increased if Model is invalidated.

Compatible with EntityFramework Core 2.0 ?

I got the following exception when attempting to migrate an existing project to .Net Core 2.0 assemblies:

- $exception {System.TypeLoadException: Method 'ApplyServices' in type 'FluentModelBuilder.Configuration.FluentModelBuilderOptionsExtension' from assembly 'FluentModelBuilder, Version=1.4.1.1411, Culture=neutral, PublicKeyToken=null' does not have an implementation. at FluentModelBuilder.Extensions.DbContextOptionsBuilderExtensions.Configure(DbContextOptionsBuilder optionsBuilder, AutoModelBuilder[] builders)

If FluentModelBuilder compatible with .Net Core 2.0?

Model Caching

Hi,
is there a way to avoid caching of model with FluentModelBuilder?
I have a database with multiple tables, all with the same structure. each table naem has a different prefix.
CREATE TABLE X000001Log([Id] [int] NOT NULL, [Date] [datetime] NOT NULL)
CREATE TABLE X000002Log([Id] [int] NOT NULL, [Date] [datetime] NOT NULL)
CREATE TABLE X000003Log([Id] [int] NOT NULL, [Date] [datetime] NOT NULL)

In an ASP .NET 5 application the model is cached the first time it has been built.
The OnModelCreating is fired only once time for the entire life cicle of the app

        private string _prefix;
        private bool _rebuildModel;

        public MyContext(string prefix, bool rebuildModel) {

            _prefix = prefix;
            _rebuildModel = rebuildModel;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder options)
        {
            options.UseSqlServer(@"Server=(local);Database=mydb;Trusted_Connection=True;");

            if (_rebuildModel)  {
                 /* what can i do here? */
            }
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<LOG>().ToTable(string.Concat(_prefix, "log"));

Any suggestion?
Thanks in advance

Replace explicit UseModel with IModelSource implementation

This way, model can be created when first requested, giving the capability for dependency injection.

Caution needs to be taken with database prociders which have their own ModelSources.

Maybe inherit from those providers and override the modelsource there?

Enable single ConventionSet item alteration

Add supporting interfaces like IEntityTypeConventionOverride, which expose an Alter(IList<IEntityTypeConvention>); method

Additionally, add an AddAlterationsFromAssembly() method to ConventionSetAlterationCollection which scans an assembly for all of those types of convention overrides.

Make Scope property accessor

class ScopeBuilder
{
private AutoModelBuilder _amb; // ctor
    public AutoModelBuilder Early()
{
    _amb.SetScope(Early);
    return amb;
}
}

Consider having assembly scanning as a separate convention

Currently, assembly scanning is a core mechanic in a few conventions, requiring specifying assemblies in both conventions separately. Consider moving assembly scanning into its own convention, and allow other conventions to call that instead.

Possible proposals:

FluentModelBuilderOptions => ModelBuilderConventionSource property
opts.UseAssemblies(x => x.Containing<Type>());
opts.AddEntities(x => x.WithBaseType<Entity>());
opts.AddOverrides();

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.