我一直在从事一个项目,需要将类更新为新版本的数据库架构。
我删除了模型类并从
App.config
中删除了引用。
完成首先添加代码 dbo 并再次将其链接到数据库(这刷新了类)的步骤之后,现在我的所有代码都返回类似于以下内容的错误:
无法将类型“System.Collections.Generic.List
”隐式转换为 System.Collections.Generic.List
发生错误的代码示例如下所示:
using MyProgram.Data;
namespace MyProgram.Interface
{
public class MyConfiguration
{
public List<MySettings> settingsList;
public SettingsConfiguration()
{
using (var context = new model1())
{
var query = from s in context.MySettings
select s;
settingsList = query.ToList();
}
}
}
}
我假设我在导入时搞砸了 model1 类或其他东西,但我不知道是什么。这个问题突然开始出现。
我预计首先从数据库导入代码只会更新类并重新生成模型类而不会出现问题。
我解决了这个问题。
当我在这里使用占位符名称时,原始代码使用了一个特定的名称,结果与我们使用的具有相同名称的 dll 中的公开对象相同。
我最终不得不返回并重命名导入的对象类。