Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成对DB First代码生成的支持 #22

Open
VictorTzeng opened this issue Jul 7, 2018 · 4 comments
Open

完成对DB First代码生成的支持 #22

VictorTzeng opened this issue Jul 7, 2018 · 4 comments
Labels
new feature 新功能

Comments

@VictorTzeng
Copy link
Owner

目前仅支持Sqlserver、MySQL、NpgSQL等三种数据库,具体用法如下:

  1. 注入DbContextOption
services.Configure<DbContextOption>(options =>
{
    options.ConnectionString =
        "User ID=zengxw;Password=123456;Host=localhost;Port=5432;Database=ZxwPgDemo;Pooling=true;";
});
  1. 注入CodeGenerateOption
services.Configure<CodeGenerateOption>(options =>
{
    options.OutputPath = "F:\\Test\\PostgreSQL";
    options.ModelsNamespace = "Zxw.Framework.Website.Models";
    options.IRepositoriesNamespace = "Zxw.Framework.Website.IRepositories";
    options.RepositoriesNamespace = "Zxw.Framework.Website.Repositories";
    options.ControllersNamespace = "Zxw.Framework.Website.Controllers";
});   
  1. 调用GenerateAllCodesFromDatabase生成所有代码
CodeGenerator.GenerateAllCodesFromDatabase(true);

生成代码文件结构图

@VictorTzeng VictorTzeng added the new feature 新功能 label Jul 7, 2018
@lemongeek
Copy link

你好,我照着以上的代码在net core 的webapi中使用使用报错;
image
StartUp中
image
调用部分:
image
请问是调用那里出的错吗?还是仅可以在mvc中controller中调用?

@VictorTzeng
Copy link
Owner Author

image
你代码注入有遗漏,请参照Demo中的注入

@lemongeek
Copy link

多谢,我尝试 了加入demo中的InitIoC ()并进行删减,并放置在步骤【注入DbContextOption】代码前。此时提示的是“未能获取到数据库上下文,请先注册数据库上下文。” 我后边继续再研究研究。

@VictorTzeng
Copy link
Owner Author

1.在Startup里面将ConfigureServices函数的返回值类型改成IServiceProvider, 如下
public IServiceProvider ConfigureServices(IServiceCollection services)
2.在所有资源都注入只有,这一句不能遗漏:
return AspectCoreContainer.BuildServiceProvider(services);//接入AspectCore.Injector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature 新功能
Projects
None yet
Development

No branches or pull requests

2 participants