开发者

DataContext Not Seeing Updates

I am using Unity 2.0 to register a concrete SQL Server repository against an abstract repository like so:

var context = new DataContext(
    ConfigurationManager.ConnectionStrings["DevDB"].ConnectionString
);

this.UnityContainer
    .RegisterType<AlertQueueRepository, Sql.AlertQueueRepository>(
        new InjectionConstructor(context)
    );

The context is being shared across all of the other repositories that I have. This works fine within the application, however, if someone else - SSMS query, SSIS package, o开发者_如何学运维ther application - modifies the database my repositories are unaware of this and will not see the change.

Is this an issue with the way I'm using Unity? Perhaps the contexts are hanging around too long? Or is it something I need to configure with LINQ?


Consider the answer to this question: Multiple application using one database?.

If you really need multiple applications to access/modify the data, consider building a layer on top of the database to service all the requests.


This question was similar to mine it turns out - ASP.NET MVC inject per request.

What I needed to do was have each request register its own context as it has the side-effect that the context gets thrown out after each request. Now I'm just left to consider the performance implications of this pattern.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜