StructureMap/ASP.MVC/Visual Studio/LinqToSql 的奇怪行为 [英] Strange behaviour with StructureMap / ASP.MVC / Visual Studio / LinqToSql

查看:33
本文介绍了StructureMap/ASP.MVC/Visual Studio/LinqToSql 的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在将新的 MVC 框架与 StructureMap 一起使用,并且总体上取得了不错的结果,但是,我一直遇到一个非常奇怪的错误,我无法理解或想出如何解决.

I have been using the new MVC framework with StructureMap recently and have had good results overall, however, I keep running into a very strange error that I cannot understand or work out how to resolve.

这是我的架构:

  • DBContext - linqToSql 数据上下文.
  • IRepository - 定义数据方法的契约.
  • IService - 定义服务方法的契约.
  • 控制器 - 在此示例中为两个.

因此我有:

public class Repo : IRepository
{
    public Repo(DBContext db)
    {
       .....
    }
}

public class Service : IService
{
    public Service(IRepository repo)
    {
       .....
    }
}

public class ControllerOne : Controller
{
    public ControllerOne(IService service)
    {
       .....
    }
}

public class ControllerTwo : Controller
{
    public ControllerTwo(IService service)
    {
       .....
    }
}

StructureMap 用于定义 IRepository 和 IService 的具体类型,DBContext 由 DSL 注册表配置的 Lamba 表达式 - () => new DBContext() 构造.

StructureMap is being used to define concrete types for IRepository and IService and the DBContext is constructed by the lamba expression - () => new DBContext() configured by DSL registry.

目前没有缓存 DBContext

进入问题:

我的索引页面加载并向 ControllerOne 和 ControllerTwo 发出两个同时的 Ajax 请求,它们是通过 MvcContrib 的 StructureMap 控制器工厂构建的.

My index page loads and makes two simultaneous Ajax requests to ControllerOne and ControllerTwo, which are constructed via the StructureMap controller factory from MvcContrib.

StructureMap 正在注入 IService 的具体类型,这些类型又是使用配置的 IRepository 实例和新的 DBContext 对象创建的.

StructureMap is injecting the concrete types of IService, which in turn are created with the configured IRepository instance and a new DBContext object.

ControllerOne 正在从 IService 实例请求模型,然后该模型作为 JsonActionResult 返回,由 Newtonsoft.Json 呈现.

ControllerOne is requesting a model from the IService instance, which is then returned as a JsonActionResult, which is rendered by Newtonsoft.Json.

ControllerTwo 正在从 IService 实例请求不同的模型,当 MVC 框架执行 ActionResult 时,它也会序列化为 Json 对象.

ControllerTwo is requesting a different model from the IService instance, which is also serialised to a Json object when the MVC framework executes the ActionResult.

我在 VS2008 中通过 Cassini 运行该网站.

I am running the website via Cassini in VS2008.

我不时看到的问题是从 LinqToSql 内部生成的错误

The problem I am seeing every now and then is an error generated from within LinqToSql

  • 无法读取数据,已有读取器打开或
  • 无法将数据加载到数据表中,因为数据已经存在(我目前没有确切的例外情况,但两者都是 LinqToSql 内部的).

如果错误发生在 ControllerOne 中,那么 ControllerTwo 也会失败,并出现类似的错误,就好像这两个请求正在使用共享对象运行一样.

If the error happens in ControllerOne then ControllerTwo will also fail with a similar error, as if the two requests are running with shared objects.

它不会一直出错,但足以让我担心我的架构以及它在某些方面的配置错误.

It doesn't error all the time but it's enough to make me concerned about my architecture and that it's configured wrong in some way.

StructureMap 是否可以在后续请求中返回相同的 ControllerOne 和 ControllerTwo 实例,或者它是否以任何方式缓存 DBContext?即使我没有要求它?

Is there any way StructureMap could be returning the same instance of ControllerOne and ControllerTwo on subsequent requests, or if it's caching the DBContext in any way? Even though I am not asking it to?

在 Visual Studio/Cassini 中工作时有没有人看到过类似的东西?通过 IIS 有帮助吗?

Has anyone seen anything similar when working within Visual Studio / Cassini? Does going through IIS help?

我应该删除 LinqToSql 吗?

Should I removed LinqToSql?

关闭 Visual Studio 并重新打开通常可以暂时解决问题.

Closing down Visual Studio and opening up again can often resolve the problem for a while.

如果有人能解决这个问题,非常感谢.

Many thanks if anyone can shed any light on the problem.

包括 NLog 日志文件中的日志片段(线程 ID 是分号前的数字):

Including logging snippet from NLog log file (thread id is number before semi colon):

03/20/2009 01:40:32 12: controller=Timesheet,date=2001-05-06,Action=WeekEnding /beta/Timesheet/2001-05-06?_dc=1237513232397 
03/20/2009 01:40:32 10: controller=Timesheet,date=2001-05-06,Action=WeekEnding /beta/Timesheet/2001-05-06?_dc=1237513232449 
03/20/2009 01:40:32 10: There is already an open DataReader associated with this Command which must be closed first. System.InvalidOperationException[br]   at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
   at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
   at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.Sum[TSource](IQueryable`1 source, Expression`1 selector)
   at HCD.Intranet.Core.Data.Linq.LinqEmployeeRepository.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding, Int32 nonProjectId)
   at HCD.Intranet.Core.Services.Impl.EmployeeService.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding)
   at HCD.Intranet.Core.Models.Timesheet.CalculateHolidaysRemaining()
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteTimesheet(JsonWriter writer, Timesheet timesheet)
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteJson(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping)
   at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at HCD.Intranet.Core.Web.Mvc.NewtonsoftJsonResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
03/20/2009 01:40:32 12: Invalid attempt to call Read when reader is closed. System.InvalidOperationException[br]   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.Sum[TSource](IQueryable`1 source, Expression`1 selector)
   at HCD.Intranet.Core.Data.Linq.LinqEmployeeRepository.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding, Int32 nonProjectId)
   at HCD.Intranet.Core.Services.Impl.EmployeeService.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding)
   at HCD.Intranet.Core.Models.Timesheet.CalculateHolidaysRemaining()
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteTimesheet(JsonWriter writer, Timesheet timesheet)
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteJson(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping)
   at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at HCD.Intranet.Core.Web.Mvc.NewtonsoftJsonResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
03/20/2009 01:41:58 12: controller=Timesheet,month=6,year=2001,Action=Calendar /beta/Timesheet/Calendar/6/2001?_dc=1237513318470 
03/20/2009 01:41:59 10: controller=Timesheet,date=2001-06-03,Action=WeekEnding /beta/Timesheet/2001-06-03?_dc=1237513318509 
03/20/2009 01:41:59 12: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type. System.InvalidOperationException[br]   at Read_TimesheetEntry(ObjectMaterializer`1 )
   at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at HCD.Intranet.Core.Data.Linq.LinqTimesheetRepository.GetEntries(Int32 timesheetHeaderId)
   at HCD.Intranet.Core.Services.Impl.TimesheetService.GetEntries(Int32 timesheetHeaderId)
   at HCD.Intranet.Core.Models.Timesheet.get_InnerEntries()
   at HCD.Intranet.Core.Models.TimeMap..ctor(Timesheet timesheet)
   at HCD.Intranet.Core.Models.Json.TimesheetCalendarJsonConverter.WriteTimesheet(JsonWriter writer, Timesheet[] timesheets)
   at HCD.Intranet.Core.Models.Json.TimesheetCalendarJsonConverter.WriteJson(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at HCD.Intranet.Core.Web.Mvc.NewtonsoftJsonResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
03/20/2009 01:41:59 12: controller=Timesheet,date=2001-06-03,Action=WeekEnding /beta/Timesheet/2001-06-03?_dc=1237513318545 
03/20/2009 01:41:59 12: There is already an open DataReader associated with this Command which must be closed first. System.InvalidOperationException[br]   at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
   at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
   at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.Sum[TSource](IQueryable`1 source, Expression`1 selector)
   at HCD.Intranet.Core.Data.Linq.LinqEmployeeRepository.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding, Int32 nonProjectId)
   at HCD.Intranet.Core.Services.Impl.EmployeeService.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding)
   at HCD.Intranet.Core.Models.Timesheet.CalculateHolidaysRemaining()
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteTimesheet(JsonWriter writer, Timesheet timesheet)
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteJson(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping)
   at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at HCD.Intranet.Core.Web.Mvc.NewtonsoftJsonResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
03/20/2009 01:41:59 10: Invalid attempt to call Read when reader is closed. System.InvalidOperationException[br]   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.Sum[TSource](IQueryable`1 source, Expression`1 selector)
   at HCD.Intranet.Core.Data.Linq.LinqEmployeeRepository.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding, Int32 nonProjectId)
   at HCD.Intranet.Core.Services.Impl.EmployeeService.CalculateHolidaysRemaining(Employee employee, DateTime weekEnding)
   at HCD.Intranet.Core.Models.Timesheet.CalculateHolidaysRemaining()
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteTimesheet(JsonWriter writer, Timesheet timesheet)
   at HCD.Intranet.Core.Models.Json.TimesheetJsonConverter.WriteJson(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonMemberMapping memberMapping)
   at Newtonsoft.Json.JsonSerializer.SerializeObject(JsonWriter writer, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at HCD.Intranet.Core.Web.Mvc.NewtonsoftJsonResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)

推荐答案

我正在和 Jeremy Miller 讨论这个问题,你不想想用 SM 管理数据库上下文的生命周期 - 让回购根据需要实例化.这给您如何进行对象更新/持久化带来了问题(如果您依赖一个上下文保持多个请求的活动状态),但是对于 Web 应用程序来说,依赖它是值得的.

I was talking to Jeremy Miller about this and you don't want to manage the lifetime of the db context with SM - let the repo instantiate as needed. This presents problems with how you will do object updating/persistence (if you're relying on a context staying alive for more than one request) but it's worth it to not rely on this for a web app.

由于这样的原因,我不得不从店面中删除数据库上下文管理的东西 - 我正在发生内存泄漏.我不会说这是 SM 的错 - 但总的来说只是让 repo 打开一个新的上下文.

I had to remove the db context management stuff from the storefront for a reason like this - I was getting memory leaks. I won't say it's SM's fault - but overall just let the repo open a new context.

这篇关于StructureMap/ASP.MVC/Visual Studio/LinqToSql 的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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