Consider a Customer
entity that has a Resource
object representing the logo of the customer:
public class Customer
{
public Guid Id { get; set; }
public string CompanyName { get; set; }
public Resource Logo { get; set; }
}
public class Resource
{
public string Uri { get; set; }
public string Name { get; set; }
}
This is what I have tried so far but getting an error because Logo is a complex object:
var customer = modelBuilder.Entity<Customer>().ToTable("Customers");
customer.HasKey(c => c.Id);
customer.Property(c => c.CompanyName).HasColumnName("Company");
customer.Property(c => c.Logo);
How can I store that Resource with EF Core 2.0 as a value object inside the customer table?
If you want to share the same table you could simply define an Owned Entity:
modelBuilder.Entity<Customer>().OwnsOne(c => c.Logo);
By convention it will use just one table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With