实体框架自我跟踪实体 - 调用 StartTracking 时出错
我将自我跟踪实体与实体框架结合使用,由于某种原因,在对实体进行更改之前调用 StartTracking() 时,我现在收到错误。
我的代码如下:
BusinessUnit BusinessUnitObject = this.settingFacade.GetBusinessUnitByID(idToGet);
BusinessUnitObject.StartTracking();
所有这一切都是使用我们拥有的 ID,使用对象上下文从数据库中读取,然后立即开始跟踪它。
错误是
Value cannot be null. Parameter name: trackingItem
在查看实体框架的实际生成代码时,抛出错误的代码是:
public static void StartTracking(this IObjectWithChangeTracker trackingItem)
{
if (trackingItem == null)
{
throw new ArgumentNullException("trackingItem");
}
trackingItem.ChangeTracker.ChangeTrackingEnabled = true;
}
参数“trackingItem”为空,但我不确定为什么。
以前有人遇到过这个吗?过去几个月我一直在使用 STE,这是第一次发生这种情况。
编辑 -------------------
抱歉,各位......在对我的代码进行了大量重构之后,我引入了一个错误,以及对象本身为 null,然后我调用 StartTracking()!
I am using Self Tracking Entities with the Entity Framework and for some reason I am now getting an error when making a call to StartTracking() before I make changes to an entity.
My code is as follows:
BusinessUnit BusinessUnitObject = this.settingFacade.GetBusinessUnitByID(idToGet);
BusinessUnitObject.StartTracking();
All this does, is use an ID that we have, use the object context to read from the database, and then start tracking on it straight away.
The error is
Value cannot be null. Parameter name: trackingItem
Upon looking at the actual generated code of Entity Framework, the code throwing the error is:
public static void StartTracking(this IObjectWithChangeTracker trackingItem)
{
if (trackingItem == null)
{
throw new ArgumentNullException("trackingItem");
}
trackingItem.ChangeTracker.ChangeTrackingEnabled = true;
}
The parameter "trackingItem" is null, but I am unsure why.
Has anyone come across this before? I have been using STE's the last couple of months and this is the first time this has happened.
EDIT -------------------
Sorry folks...after a lot of refactoring of my code I have introduced a bug, and the object itself was null, which I was then calling StartTracking() on!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论