Skip to content

EntityFrameworkCore 的扩展,通过反射注册实体模型。

License

Notifications You must be signed in to change notification settings

jgh004/ITnmg.EntityFrameworkCore.Extensions

Repository files navigation

ITnmg.EntityFrameworkCore.Extensions

EntityFrameworkCore 的扩展,通过反射注册实体模型。

Install

Run the following command in the Package Manager Console.
在 nuget 包管理器控制台输入以下命令

PM> Install-Package ITnmg.EntityFrameworkCore.Extensions

Getting Started

In the model dll

public class Order : IEntityTypeConfiguration<Order>
{
    public string Id { get; set; }

    public void Configure( EntityTypeBuilder<Order> builder )
    {
        base.Configure( builder );
        builder.Property( m => m.Id ).HasMaxLength( 255 ).IsRequired();
    }
}

In the context dll

public class EFContext : DbContext
{
    public EFContext( DbContextOptions options ) : base( options )
    {
    }

    protected override void OnModelCreating( ModelBuilder modelBuilder )
    {
        base.OnModelCreating( modelBuilder );
        modelBuilder.ApplyConfigurationFromAssembly( Assembly.GetExecutingAssembly() );
    }
}

In the application

EFContext db = new EFContext(...);

public void Main(...)
{
    var order = db.Set<Order>().FirstOrDefault();
}

About

EntityFrameworkCore 的扩展,通过反射注册实体模型。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages