Tag: entity framework核心

ASP.NET Core EF命令:无法连接到任何指定的MySQL主机

更新:发现,我有一个Dockerfile的责任误解。 当一个容器被构build时,完全的networking是不可行的。 总之,最好的做法似乎是在一个容器中应用迁移,稍后将其移除。 我想多写一点,稍后会给出更详细的答案。 我正在基于Jenkins的基于MySQL的数据库(MariaDB)的ASP.NET核心应用程序CI部署。 应用程序内部的MySQL Connection for Entity Framework Core工作,例如用于ASP.NET Core Identity。 当我尝试使用dotnet ef database update应用数据库迁移时,我总是得到以下exception: MySql.Data.MySqlClient.MySqlException:无法连接到任何指定的MySQL主机。 听起来像是连接问题,但事实并非如此:当我运行我的应用程序没有迁移,我看到ASP.NET核心可以查询数据库,并给我例外,表不存在。 我也使用VPN迁移到SQL服务器容器:Works。 我甚至在托pipeASP.NET Core应用程序的Container上安装了MySQL cmd客户端,并与它们连接,也起作用: root@efc609a9a9aa:/app/test/test# dotnet ef database update -e Development Build succeeded. 0 Warning(s) 0 Error(s) Time Elapsed 00:00:04.56 CONNECTIONSTRING = Server=mariadb; Database=test; Uid=root; Pwd=test; MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL […]

在Asp.Net Core中使用两个上下文进行数据库迁移(Docker上的SQL Server)

我的应用程序中有两个上下文。 一个在WebApi Project -> ApiContext (inherited from IdentityDbContext) ,另一个在Infrastructure -> Context 。 我使用Docker Engine( microsoft/mssql-server-linux )的Linux上的Microsoft SQL Server的官方图像。 我写了一个DbFactory 。 下面你可以find我的代码。 ApiContext:内部类ApiContext:IdentityDbContext {公共ApiContext(DbContextOptions选项):基地(选项){Database.EnsureDeleted(); } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); } } 上下文 内部类上下文:DbContext {公共上下文(DbContextOptions选项):基地(选项){Database.EnsureCreated(); } public DbSet<Reservation> Reservations { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<Table>().ToTable("Table"); } } 在我的基础设施项目中,我曾经说过DbFactory […]

debugging/释放asp.net 4.6.2 mvc应用程序不与视觉工作室docker支持工作

我开发了一个简单的.NET应用程序,在不使用docker支持的情况下进行debugging时效果很好。 后来我join了docker support docker-compose项目,添加了下面的文件。 而现在我正在接受错误。 我已经将docker改为windows容器,并将docker-compose项目设置为默认的docker-compose.yml version: '3' services: pakuberdriver: image: pakuberdriver build: context: .\PakUberDriver dockerfile: Dockerfile DockerFile.file FROM microsoft/aspnet:4.6.2 ARG source WORKDIR /inetpub/wwwroot COPY ${source:-obj/Docker/publish} . 以下是构build输出 **1>—— Build started: Project: docker-compose, Configuration: Debug Any CPU —— 1>docker version –format {{.Server.Os}} 1>windows 1>docker-compose -f "C:\Users\ahsansadeque\source\repos\PakUberDriver\docker-compose.yml" -f "C:\Users\ahsansadeque\source\repos\PakUberDriver\docker-compose.override.yml" -p dockercompose5514737578020878541 config 1>networks: 1> default: 1> […]

Docker上的Asp.Net Core + SQL Server – 启动数据库的睡眠

我注意到,当我第一次尝试运行docker-compose up命令时出现错误: Starting mssql … Starting mssql … done Recreating api … Recreating api … done Attaching to mssql, api api exited with code 1 因为api尝试从数据库获取数据,但MSSQL尚未启动。 所以,我的问题是有可能以某种方式等待数据库,然后运行API? 这是我的docker-compose和dockerfile docker-compose:version:'3.3' 服务: api: image: api container_name: api build: context: . dockerfile: Dockerfile ports: – "8000:80" depends_on: – db db: image: "microsoft/mssql-server-linux" container_name: mssql environment: SA_PASSWORD: "testtest3030!" ACCEPT_EULA: […]

运行entity framework生成的DDL脚本不会在Docker容器中创build表

所以我决定,今天将是我第一次真正动手Docker的一天。 我想要一个Oracle XE容器,以便在运行集成和/或最终2端testing时快速启动和接种数据库。 我一直在使用这个Dockerfile 。 提到的.sql文件已经生成如下: create_schema.sql :没有生成,只是设置我们的ORP用户并授予pipe理员权限。 create_ddl.sql :通过在Nuget包pipe理器控制台中使用命令Update-Database -SourceMigration $InitialDatabase -Script生成。 create_dml.sql :从Toad For Oracle导出种子数据。 运行脚本时, create_ddl.sql不会创build任何表,导致create_dml.sql失败,因为找不到它所引用的表。 我现在有点卡住了。 当我用Toad For Oracle创buildDDL导出时,脚本运行正常。 但是,我宁愿使用与用于开发和部署的DDL脚本相同的脚本。 我猜这个失败与Entity Framework生成的迁移历史logging有关,但是我不知道为什么。 如果有人能指出我的方向,那就太好了。

MySQL MV6与MVC5和DNX

我有一个MVC5项目,使用MySQL.Data.Entity.EF6,我试图加载使用Kestrel(DNX)。 但是,我在页面负载上继续出现这个错误: MetadataException: Schema specified is not valid. Errors: CMaxModel.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. 我用这个configuration创build了我的DbContext : public class MyDbConfiguration : DbConfiguration { public […]

EF核心迁移使用asp.net核心,SQL Server和Docker产生dotnet SDK错误

我使用Docker for Windows版本1.13.0-rc5-beta35(9606) Windows 10专业版 Visual Studio代码 我已经使用yeoman生成器创build了一个使用Docker的ASP.NET Core项目: yo aspnet yo docker 当我试图让API从Docker容器连接到我本地运行的SQL Server实例时,遇到了一些问题。 为了解决这个问题,我创build了一个在自己的容器中运行的SQL Server实例(使用microsoft/mssql-server-linux映像)。 两个容器都在运行,并连接到同一个用户定义的网桥。 如果我打开我的asp.net核心容器中的bashterminal并运行命令: dotnet ef migrations add InitialMigration 我希望我的代码优先模型将在运行在networking上的SQL Server实例中创build,因为当我在本地运行安装程序(无容器)时会发生这种情况。 相反,我得到如下: Did you mean to run dotnet SDK commands? Please install dotnet SDK from: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409 我很困惑,因为我必须安装dotnet。 我已经使用microsoft/aspnetcore作为我的Dockerfile中的基础层,我可以看到,这反过来使用microsoft/dotnet:1.0.3-runtime因为它的基本层… 有人可以解释为什么我得到这个消息,如果我正在接近这个解决scheme正确的方式(Web API和SQL Server在不同的容器中)? 如果我确实需要安装dotnet sdk,我将不胜感激,如果有人能告诉我如何做Dockerfile的一部分 谢谢你的帮助 asp.net核心Dockerfile的内容 FROM microsoft/aspnetcore:1.1.0 WORKDIR /app COPY […]

add-migration:无法将参数绑定到参数“Path”,因为它是一个空string

我在Docker支持的Visual Studio 2017上运行默认的api核心项目,每次运行命令add-migration -name name add-migration:无法将参数绑定到参数“Path”,因为它是一个空string。 在行中:1 char:1 + add-migration + ~~~~~~~~~~~~~ + CategoryInfo:InvalidData:(:) [Add-Migration],ParameterBindingValidationException + FullyQualifiedErrorId:ParameterArgumentValidationErrorEmptyStringNotAllowed,Add-Migration PS:这个命令不需要docker支持,但是当我添加docker支持的时候返回这个错误