However if you start using deferred loading you may notice that it is smarter to keep the datacontext alive for as long as the front-end is using the objects retrieved from the datacontext. Static data contextsĭataContexts in Linq to SQL are IDisposable, meaning that they probably use unmanaged resources or resources that shouldn’t be kept in memory for a longer period of time. When this happens the encapsulation is gone and you will end up with errors and security leaks that take quite a bit of time to track down, since you don’t know that people went through the datacontext directly instead of your service that is secured. It’s not a matter if other developers will use it, but rather a matter of when. The main concern with exposing Linq to SQL objects in a contract is the fact that the datacontext is also exposed and will be used by others in means that you never thought off. It does save you quite a bit of code and time, but it’s what you get back that will consume the most time after that. Mind you, this only works when using conceptual services without employing techniques like WCF. The logical choice would be to place the DBML at a location that is accessible to the consumers of the service. You need to define datacontracts for quite a lot of entities that, when you use Linq to SQL reside inside your DBML too. Using Linq to SQL objects in datacontractsīuilding services that expose certain domain types requires a lot of code most of the time. The idea is to show some principals that me and others on the team have encountered and what you can do to prevent the same errors from happening when you use Linq to SQL in a real-world application. It has led to some interesting patterns and anti-patterns which I want to share in this article. Currently I’m hard at work on a project where we use Linq to SQL quite a lot.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |