1

Does it makes sense to introduce an abstract IdableEntity base class, that has a public Guid Id { get; set;} property, and then derive all my entities from it, so I don't have to add key field to each one of them? Will I face any pitfalls if I do in theory?

I used to never do this since my DbContext model was rather simple and consisted of a few classes. Now I am designing a large entity number model that may benefit from it.

4

1 回答 1

1

Speaking from experience of this exact thing - yes it makes sense. Note that this EF base class doesn't have to be the heirarchical root though - it could inherit from a base class that implements things like INotifyPropertyChanged, IChangeTracking, etc. So your inheritance chain would look like this:

BaseDataClass <- BaseEFDataObject <- [actual EF entities]

于 2012-08-02T23:28:43.640 回答