我的 DTO 对象没有通过数据上下文保存在数据库中,为什么?

发布于 2024-09-25 17:04:21 字数 241 浏览 0 评论 0原文

我正在开发一个项目,我们正在使用 MVVM 和 Wcf ria 服务。由于外键的描述必须在 UI 上的网格中显示,所以我不得不求助于使用 dtos 来完成连接来自不同表的查询并返回描述的工作。

现在的问题是,当我想保存并在编辑后使用 context.attach(entity) 时,会出现错误消息,指出具有此标识的对象已经存在。我在连接之前尝试分离,但仍然是同样的事情,没有变化。

有人可以帮我吗?提前致谢。

查尔斯.

i am working on a project and we are using MVVM and Wcf ria services. because of the headache posed by foreign keys whose description must be displyed in grids on UI, i had to resort to using dtos that do the work of joining queries from different tables and returning the descriptions.

now the problem is tha when i want to save and i use context.attach(entity) after editing, the error message comes up saying an object with this identity already exists. i tried detaching before attaching and its still same thing no changes.

can sombody help me out? thanks in advance.

charles.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┈┾☆殇 2024-10-02 17:04:21

我想你会做这样的事情:

var db = new MyDataContext();
var myEntity = db.Entities.Single(x=>x.Id = dto.Id);
myEntity.Value = dto.Value;
db.SaveChanges();

I think you'd do something like this:

var db = new MyDataContext();
var myEntity = db.Entities.Single(x=>x.Id = dto.Id);
myEntity.Value = dto.Value;
db.SaveChanges();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文