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

前端 未结 4 570
太阳男子
太阳男子 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:34

    Setting DataContext Connection property to 'None' worked for me. Steps below.

    Open the dbml -> Right Click Properties -> Update Connection in DataContext properties to 'None'. This will remove the empty constructor from the generated code file. -> Create a new partial class for the DataContext with an empty constructor like below

    Partial Class MyDataContext    
        Public Sub New()             
            MyBase.New(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString, mappingSource)
            OnCreated()    
        End Sub    
    End Class
    

提交回复
热议问题