gpt4 book ai didi

c# - 分离 POCO 类后尝试从数据库更新 EDMX 时出现 COMException

转载 作者:行者123 更新时间:2023-11-30 18:23:01 24 4
gpt4 key购买 nike

当 Test.edmx、Test.context.tt 和 Test.tt 都在一起时,我能够毫无问题地从数据库更新 edmx。

在将 Test.tt 类与 EDMX 分离并将其移动到所有 POCO 类所在的新项目后,我在尝试更新 edmx 时开始看到以下异常。

An exception of type 'System.Runtime.InteropServices.COMException' occurred while attempting to update from the database. The exception message is: 'A file or folder with the name 'Test.Context.tt' already exists. Please give a unique name to the item you are adding, or delete the existing item first.'.

环境

带有更新 5 的 Visual Studio 2013

Entity Framework 6.1.3

.NET 框架 4.5.1

控制台应用程序和类库。

最佳答案

我遇到了同样的问题,我急于寻找解决方案,但最后发现忽略异常并没有坏处。它只是尝试重写 tt 文件,并不是真正更新模型的必要步骤。

edmx 按预期更新,您可以为散布在各处的 tt 文件运行自定义工具,它们会很好地工作。只需确保所有 tt 文件都链接到 edmx 文件即可。

const string inputFile = @"..\YourProject\Model.edmx";

关于c# - 分离 POCO 类后尝试从数据库更新 EDMX 时出现 COMException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32911781/

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