tchelidze
tchelidze

Reputation: 8308

Store ValueObject in Database using ASP.NET Boilerplate

Trying to implement DDD using ASP.NET Boilerplate and Entity Framework

Employee object

public class Employee : Entity<long>
{
   public virtual string Name { get; protected set; }

   public virtual Nationality Nationality { get; protected set; }
}

defines property Nationality, which is value object

public class Nationality : ValueObject<Nationality>
{      
    public virtual string Name { get; protected set; }
}

Attempt to add database migration produces obvious error

EntityType 'Nationality' has no key defined. Define the key for this EntityType.

Took a look at 3 different approach to persist value object in database

Should i implement one of the above mentioned method manually to persist ValueObject (if so what are some of the best practices) ? or it's already done by ASP.NET Boilerplate Framework ?

Upvotes: 4

Views: 933

Answers (1)

prabakar
prabakar

Reputation: 11

when you use Value object should not use virtual on the Nationality property on the Employee object. Remove the virtual keyword. that should fix it. Use Virtual only when you reference an entity type. Also you can get rid of virtual on the Nationality.Name property.

Upvotes: 1

Related Questions