简体   繁体   English

如何在ASP.NET Web API项目中使用另一个项目的ApplicationDbContext?

[英]How to use an ApplicationDbContext from another project in a ASP.NET web API project?

I'm trying to make a web API that connects to a server and substracts the information from a data base on that server. 我正在尝试创建一个连接到服务器的Web API,并从该服务器上的数据库中减去信息。

I referenced the models from other project which connects to the same server and the same DB. 我引用了连接到同一服务器和同一个DB的其他项目中的模型。 But when I'm trying to scaffold a model class to get the controller I can't select my ApplicationDbContext who is already on my referenced models. 但是当我试图使用模型类来获取控制器时,我无法选择已经在我引用的模型上的ApplicationDbContext。

Illustrative image 说明性的图像

I expected the ApplicationDbContext to be shown as an option of Data Context Class. 我希望ApplicationDbContext显示为数据上下文类的选项。

To get an easy solution I made a class where to make the connection and requests to the data base using OleDB class in another class. 为了得到一个简单的解决方案,我创建了一个类,在另一个类中使用OleDB类建立连接和对数据库的请求。

If annyone knows how to do the same but better, I'll appreciate the help. 如果annyone知道如何做同样但更好,我会很感激帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从另一个项目初始化ASP.NET Core Web API - Initialize ASP.NET Core Web API from another project 如何在同一项目中的ASP.NET MVC控制器中从ASP.NET Web API获取数据 - How get data from asp.net web api in asp.net mvc controller in the same project 在 web api 项目中使用 asp.net mvc - Use asp.net mvc within a web api project 如何在ASP.NET Web API项目而不是.NET Core上使用DI - How do I use DI on asp.net web api project not .net core ASP.NET 内核 Web API - 如何在 ApplicationDbContext 上的 SaveChangesAsync 中实现当前用户名 - ASP.NET Core Web API - How to implement Current UserName in SaveChangesAsync on ApplicationDbContext 如何在 ASP.NET Core Web API 项目中设置 cookie - How to set a cookie in a ASP.NET Core Web API project 在 asp.net core 上使用来自不同项目的另一个控制器 - Use another controller from different project on asp.net core 如何设置 ASP.Net 3.0 Core Web API 项目以使用 AutoFac 和 NLog? - How do you setup an ASP.Net 3.0 Core Web API project to use AutoFac and NLog? 如何在ASP.NET Web-API项目中将FluentValidation与LightInject一起使用 - How to use FluentValidation with LightInject in asp.net web-api project 使用来自ASP.NET Web窗体项目的会话在Web API项目中进行身份验证 - Authentication in Web API project using the session that is from ASP.NET Web Forms project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM