我花了很多时间(谷歌搜索,反映.net二进制文件等)试图解决以下问题:
我在应用程序中看到了死锁(ASP.NET MVC + EF4).我们有几个EF的上下文,它们是在请求开始时创建的,并在最后被处理掉.有时我们会遇到以下情况:ASP.NET为每个请求创建一个线程,然后线程在访问EF上下文时进入"处于join或sleep"状态.
大多数死锁线程都有一个堆栈跟踪如下:
System.dll!System.ComponentModel.TypeDescriptor.Refresh(object component, bool refreshReflectionProvider) + 0x97 bytes
System.Data.dll!System.Data.SqlClient.SqlCommand.DesignTimeVisible.set(bool value) + 0x22 bytes
System.Data.dll!System.Data.SqlClient.SqlCommand.SqlCommand(System.Data.SqlClient.SqlCommand from) + 0xc9 bytes
System.Data.dll!System.Data.SqlClient.SqlCommand.Clone() + 0x27 bytes
System.Data.dll!System.Data.SqlClient.SqlCommand.System.ICloneable.Clone() + 0x9 bytes
System.Data.Entity.dll!System.Data.Common.DbCommandDefinition.CreateCommandDefinition(System.Data.Common.DbCommand prototype) + 0x47 bytes
System.Data.Entity.dll!System.Data.SqlClient.SqlProviderServices.CreateDbCommandDefinition(System.Data.Common.DbProviderManifest providerManifest, System.Data.Common.CommandTrees.DbCommandTree commandTree) + 0x21 bytes
System.Data.Entity.dll!System.Data.EntityClient.EntityCommandDefinition.EntityCommandDefinition(System.Data.Common.DbProviderFactory storeProviderFactory, System.Data.Common.CommandTrees.DbCommandTree commandTree) + 0x2a1 bytes
System.Data.Entity.dll!System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(System.Data.Common.DbProviderManifest providerManifest, System.Data.Common.CommandTrees.DbCommandTree commandTree) + 0x8e bytes
System.Data.Entity.dll!System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(System.Data.Objects.ObjectContext context, System.Data.Common.CommandTrees.DbQueryCommandTree tree, System.Type elementType, System.Data.Objects.MergeOption mergeOption, System.Data.Objects.Span span, System.Collections.ObjectModel.ReadOnlyCollection<System.Collections.Generic.KeyValuePair<System.Data.Objects.ObjectParameter,System.Data.Objects.ELinq.QueryParameterExpression>> compiledQueryParameters) + 0x113 bytes
System.Data.Entity.dll!System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(System.Data.Objects.MergeOption? forMergeOption) + 0x310 bytes
System.Data.Entity.dll!System.Data.Objects.ObjectQuery<CompuTool.Business.Portal.Desktop>.GetResults(System.Data.Objects.MergeOption? forMergeOption) + …Run Code Online (Sandbox Code Playgroud) 给出2个字符串s和t.我需要找到s编辑距离(Levenshtein距离)中的每个子串t.实际上我需要知道每个i位置在s所有从位置开始的子串的最小编辑距离i.
例如:
t = "ab"
s = "sdabcb"
Run Code Online (Sandbox Code Playgroud)
我需要得到类似的东西:
{2,1,0,2,2}
说明:
1st position:
distance("ab", "sd") = 4 ( 2*subst )
distance("ab", "sda") = 3( 2*delete + insert )
distance("ab", "sdab") = 2 ( 2 * delete)
distance("ab", "sdabc") = 3 ( 3 * delete)
distance("ab", "sdabcb") = 4 ( 4 * delete)
So, minimum is 2
2nd position:
distance("ab", "da") = 2 (delete + insert)
distance("ab", …Run Code Online (Sandbox Code Playgroud) string algorithm edit-distance similarity levenshtein-distance
据我所知,Entity Framework实现了Identity Map Pattern,因此EF会在内存中缓存一些实体.
我举个例子吧.
var context = new StudentContext();
var student = context.Students.Where(st => st.Id == 34).FirstOrDefault();
// any way of changing student in DB
var anotherContext = new StudentContext();
var anotherStudent = anotherContext.Students.Where(st => st.Id == 34).FirstOrDefault();
anotherStudent.Name = "John Smith";
anotherContext.SaveChanges();
student = context.Students.Where(st => st.Id == 34).FirstOrDefault();
// student.Name contains old value
Run Code Online (Sandbox Code Playgroud)
有没有办法使第一个上下文的缓存无效并检索新student实体而无需重新创建上下文?
感谢帮助.
.net caching entity-framework identity-map entity-framework-4
在加载某些程序集时,ASP.NET是否将所有依赖项程序集(位于BIN文件夹中)加载到默认的appdomain?或者它将"按需"加载(当CLR需要依赖程序集中的某种类型时)?
.net ×3
algorithm ×1
appdomain ×1
c# ×1
caching ×1
deadlock ×1
identity-map ×1
similarity ×1
string ×1