实体框架存储过程异常 [英] Entity Framework Stored Procedures Exception

查看:104
本文介绍了实体框架存储过程异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下实体框架模型:

I have the following Entity Framework model:

这是一个非常简单的模型,在Entity Framework生成SQL时工作正常。当我将实体映射到存储过程时,尝试创建一个 LogEntry 时,会收到以下错误:

It's a very simple model and was working fine when Entity Framework was generating the SQL. When I mapped the entities to stored procedures I get the following error when trying to create a LogEntry:


无法确定依赖操作的有效排序。由于外键约束,模型要求或存储生成值,可能存在依赖关系。

Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.

我正在使用的代码进行LogEntry如下所示:

The code I am using to make a LogEntry looks like the following:

le.DateAndTime = DateTime.Now;
le.User = (Guid)Membership.GetUser().ProviderUserKey;

Log log = lr.GetLog(le.LogId);
log.LogEntries.Add(le);

lr.Save(); // lr is an instance of LogsRepository, defined earlier in the class

之前定义的异常不会抛出,直到 lr.Save()被调用。

The exception isn't thrown until lr.Save() is called.

有人可以帮我解读吗?我有存储过程,所有工作都独立于实体框架,映射到实体。

Can anybody help me decipher this? I have stored procedures which all work on their own, independent of entity framework, mapped to the entities.

推荐答案

我设法弄清楚导致错误的原因。看看以下映射设置:

I managed to figure out what was causing the error. Take a look at the following mapping setup:

正如你所看到的,我有一个结果列绑定从 UpdateLog ,问题是 UpdateLog 不返回任何内容。我不小心把它放入了映射。删除结果列后,所有内容都可以重新生效。

As you can see, I had a result column binding from UpdateLog, problem being that UpdateLog doesn't return anything. I accidentally put this into the mapping. After deleting the result column binding everything works again.

这篇关于实体框架存储过程异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆