继Julia Lermas在跟踪变化的N层解决方案上预订'DbContext'后,我为每个实体提供了一个State属性和一个OriginalValues字典(通过IObjectWithState).构造实体后,我将原始值复制到此字典.请参阅本书的示例(4-23):
public BreakAwayContext()
{
((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized += (sender, args) =>
{
var entity = args.Entity as IObjectWithState;
if (entity != null)
{
entity.State = State.Unchanged;
entity.OriginalValues = BuildOriginalValues(this.Entry(entity).OriginalValues);
}
};
}
Run Code Online (Sandbox Code Playgroud)
在BreakAwayContext的构造函数(继承自DbContext)中捕获ObjectMaterialized事件.要检索实体的原始值,通过调用this.Entry(entity)从上下文中检索DbEntityEntry.此调用正在减慢进程.此事件处理程序的80%的时间花费在此调用上.
是否有更快的方法来检索原始值或实体DbEntityEntry?
我有一个 ajax 请求返回数据以显示带有复选框的树。在从 ajax 调用返回的 de html 数据中,项目的检查状态是使用自定义 data-checkstate 属性定义的。如何在树中恢复此检查状态?
预期结果:

<head>
<meta charset="utf-8" />
<title>JsTree test</title>
<link rel="stylesheet" href="http://static.jstree.com/latest/assets/dist/themes/default/style.min.css" />
<script src="http://static.jstree.com/latest/assets/dist/libs/jquery.js"></script>
<script src="http://static.jstree.com/latest/assets/dist/jstree.min.js"></script>
</head>
<body>
<div id="container"/>
</body>
</html>
<script>
$(function () {
var ajaxResponse =
'<ul> <li data-checkstate="undetermined">Parent 1' +
' <ul>' +
' <li data-checkstate="unchecked">Child 1a' +
' <ul>' +
' <li data-checkstate="unchecked">Grantchild 1a1</li>' +
' <li data-checkstate="unchecked">Grantchild 1a2</li>' +
' </ul>' +
' </li>' +
' <li data-checkstate="undetermined">Child 1b' +
' <ul>' +
' <li …Run Code Online (Sandbox Code Playgroud) 我使用的是Windows 7 x64.启动MVC应用程序时出现BadImageFormatException.如果它在启用了32位应用程序的应用程序池中运行,则不会抛出异常.看起来像加载global.asax是个问题.我启用了融合日志记录(HKLM\software\Microsft\Fusion!EnableLog)注册表设置.这是日志:
=== Pre-bind state information ===
LOG: User = NT AUTHORITY\SYSTEM
LOG: Where-ref bind. Location = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\spl.sim.mvc\5802065c\a2782d40\App_global.asax.olejmmua.dll
LOG: Appbase = file:///C:/Spl/SimSvn4.5/Source/Spl.Sim.Mvc/
LOG: Initial PrivatePath = C:\Spl\SimSvn4.5\Source\Spl.Sim.Mvc\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Spl\SimSvn4.5\Source\Spl.Sim.Mvc\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using …Run Code Online (Sandbox Code Playgroud)