Is there a way to override the empty constructor in a class generated by LINQtoSQL?

前端 未结 4 543
太阳男子
太阳男子 2021-01-17 17:49

If I have a table in my database called \'Users\', there will be a class generated by LINQtoSQL called \'User\' with an already declared empty constructor.

What is t

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 18:38

    Here's the C# version:

    public partial class PENCILS_LinqToSql_DataClassesDataContext
    {
         public PENCILS_LinqToSql_DataClassesDataContext() : base(ConnectionString(), mappingSource)
        {
        }
    
        public static String ConnectionString()
        {
            String CS;
            String Key;
    
            Key = System.Configuration.ConfigurationManager.AppSettings["DefaultConnectionString"].ToString();
    
            /// Get the actual connection string.
            CS = System.Configuration.ConfigurationManager.ConnectionStrings[Key].ToString();
    
            return CS;
        }
    }
    

提交回复
热议问题