Will linqtosql take care if many threads are accessing the same table of the database at the same time?
I am working on a asp.net mvc application. I have a situation where I have to make many threads which are going to access the database using linqtosql. My question is, will it be fine to leave every thing on linqtosql to maintain the synchronization, because the threads will be accessing the database at the same time. Or I have to write my own code to d开发者_JAVA技巧o that.
If each thread is using its own database context, you will be fine. However, I don't believe the database context object is thread safe. So, it's best to make sure each thread has its own context.
Randy
I'm not sure what kind of synchronization you mean, but databases have been designed such that multiple clients (threads, processes, machines) can access/read/change data at the same time. Linq2Sql is - speaking very simply - just one of the mechanisms to emit SELECT/DELETE/UPDATE statements against the database.
If you are using ASP.NET MVC I would seriously take a look at using S#arp Architecture. It uses nHibernate but provides some scaffolding to make the data layer very easy to create and work with. It uses fluent nhibernate and the AutoPersistenceModel so there is no need to play with XML files for mappings. It also includes a number of very handy to have MVC tools.
Linq2SQL seems to have some pretty serious shortcomings whenever I've tried to do anything remotely sophisticated with it and I would probably only recommend it for very simple scenarios. Perhaps it's just me but I have observed some pretty ugly behaviour with L2S.
精彩评论