开发者

Linq2sql: how to 'inherit' data context from custom interface?

开发者 https://www.devze.com 2023-01-26 04:08 出处:网络
After generation of DataContext class from my DB I\'ve got CMCoreDataClassesDataContext class. For unit-testing purpose I would like this class to be implementing my special interface, ICMCoreDataCla

After generation of DataContext class from my DB I've got CMCoreDataClassesDataContext class.

For unit-testing purpose I would like this class to be implementing my special interface, ICMCoreDataClassesDataContext. I could change desi开发者_StackOverflow社区gner.cs class but it will need to be updated each time when regenerated.

Is there any solution that allows to mark auto-generated class as to be inherited from my interface? I see possibility to change base class, but how can I specify 'base' interface?

P.S. Is it an option to create a base class that will be inherited from System.Data.Linq.DataContext AND my interface (ICMCoreDataClassesDataContext) and specify it as a base class for autogenerated one? It doesn't work due to necessity to declare required methods as abstract in base class (that is OK) and mark them with "override" in generated.

P.S. .NET 3.5, Linq2sql


The generated datacontext is a partial class. You can add a separate .cs file with the following:

public partial class MyDataContext : IMyInterface
{} 
0

精彩评论

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

关注公众号