using Microsoft.EntityFrameworkCore; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Modeling; using ZL.AbpNext.Poem.Core.Poems;
namespace ZL.AbpNext.Poem.EF.EntityFramework { [ConnectionStringName("Poem")] public class PoemDbContext : AbpDbContext<PoemDbContext>,IPoemDbContext { public virtual DbSet<Poet> Poets { get; set; }
public PoemDbContext(DbContextOptions<PoemDbContext> options) : base(options) { }
using Microsoft.Extensions.DependencyInjection; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Modularity; using ZL.AbpNext.Poem.Core; using ZL.AbpNext.Poem.EF.EntityFramework;
namespace ZL.AbpNext.Poem.EF { [DependsOn( typeof(PoemCoreModule), typeof(AbpEntityFrameworkCoreModule) )] public class PoemDataModule:AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAbpDbContext<PoemDbContext>(options => { options.AddDefaultRepositories(includeAllEntities: true); });
Configure<AbpDbContextOptions>(options => { /* The main point to change your DBMS. * See also BookStoreMigrationsDbContextFactory for EF Core tooling. */ options.UseSqlServer(); }); } } }
using Volo.Abp.Modularity; using ZL.AbpNext.Poem.Core; using ZL.AbpNext.Poem.EF;
namespace ZL.AbpNext.Poem.ConsoleClient { [DependsOn( typeof(PoemCoreModule), typeof(PoemDataModule))] public class PoemConsoleClientModule:AbpModule {
using System; using System.Linq; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; using Volo.Abp.Uow; using ZL.AbpNext.Poem.Core.Poems;
namespace ZL.AbpNext.Poem.ConsoleClient { public class Service : ITransientDependency { IRepository<Poet> repository; IUnitOfWorkManager uowManager; public Service(IRepository<Poet> repository, IUnitOfWorkManager uowManager) { this.repository = repository; this.uowManager = uowManager; } public void Run() { //Console.WriteLine("你好"); using (var uow = uowManager.Begin(new AbpUnitOfWorkOptions())) { //获取第一个诗人 var poet = repository.FirstOrDefault();