I saw similar questions, but they are not quite what I mean (or maybe they are, and I do not understand the answers)
In my previous application using Linq2SQL, I was able to overload the constructors with parameters by doing the following:
Namespace CoreDb
Partial Public Class Accomplishment
Public Sub New(ByVal accomplishmentTypeID As Object, ByVal description As String, ByVal title As String, ByVal applicableDate As DateTime, ByVal lastUpdatedBy As String)
Me.New()
If TypeOf (accomplishmentTypeID) Is Guid Then
Me.AccomplishmentTypeId = accomplishmentTypeID
End If
If TypeOf (accomplishmentTypeID) Is String Then
Me.AccomplishmentTypeId = New Guid(accomplishmentTypeID.ToString())
End If
Me.Description = description
Me.ApplicableDate = applicableDate
Me.Title = title
Me.Id = Guid.NewGuid()
Me.DateCreated = DateTime.Now
Me.DateModified = DateTime.Now
Me.LastUpdatedBy = lastUpdatedBy
Me.CreatedBy = lastUpdatedBy
End Sub
End Class
End Namespace
Basically, using a partial class for an object, splitting the namespace of the .dbml file and calling the default constructor, and then performing additional actions.
So then in my code I could do something like:
Dim accomplishment As New Accomplishment(id, description, title, applicableDate, lastUpdatedBy)
This does not seem to work in the Entity Framework anymore, since the default constructor does not exist.
Is it really not working anymore? And if so, what is a good alternative to implementing something like that?