Flatten complex object on entity in DB

c# entity-framework-core

Question

Let's say I have the following items:

Entity:

public class MyEntity : NamedEntity
{
}

public abstract class NamedEntity : VersionedEntity
{
    public LocalizedText Name { get; set; }
}

Object complex (localizedText):

public class LocalizedText : ILocalized<string>
{
    protected LocalizedText()
    {
    }

    public LocalizedText(string en, string de = null, string fr = null)
    {
        En = en;
        De = de;
        Fr = fr;
    }

    public string En { get; set; }
    public string De { get; set; }
    public string Fr { get; set; }
}

I got the following exception with this:

System.InvalidOperationException: 'The entity type 'LocalizedText' requires a primary key to be defined.'

I don't want to turn this into an entity.LocalizedText , but would want it to be saved in the database in the Name EN, Name DE, and Name FR columns of the MyEntity table.

How can I do this?

1
0
10/8/2018 12:13:40 PM

Popular Answer

ZZZ_tmp
0
10/8/2018 2:17:07 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow