gpt4 book ai didi

c# - Entity Framework Core 2 中的 ConnectionString Builder

转载 作者:太空宇宙 更新时间:2023-11-03 14:56:13 25 4
gpt4 key购买 nike

我正在尝试将旧项目 c# 转换为 asp net core 和 EF core 2.0,但找不到 EntityConnectionStringBuilder。

public string GetEntityConnectionString(string databaseName, string metadata)
{
string providerName = "System.Data.SqlClient";
string providerString = GetConnectionString(databaseName);


System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder entityBuilder =
new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder();

Error CS0234 The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

最佳答案

那是因为 EF Core 不支持旧 EF 版本的所谓“数据库优先”方法,因此没有 edmx 文件,因此没有使用 EF 特定连接字符串 (metadata=res:. .. < 这种连接字符串)。由此可见,用于创建此类连接字符串的 EntityConnectionStringBuilder 类没有用处。

因此,在移植时,只需删除整个 GetEntityConnectionString 方法并使用 GetConnectionString 以及 UseSqlServerUsePgsql 和类似的方法。

关于c# - Entity Framework Core 2 中的 ConnectionString Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48904635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com