0

I have the following model

public class Locale
{ 
    public int Id { get; set; }
    public ICollection<Localization<Locale>> Localizations { get; set; }
}

public class Localization<T>
{
    public int Id { get; set; }
    public Locale Locale { get; set; }
    public string DisplayName { get; set; }
    public T Entity { get; set; }
}

In this case, I want to be able to localize any entity, include the localization itself (ie: for places where we show available languages in the users language ).

I have this working in NHibernate, but I need to move to EF. The issue arises when I want to use the fluent API to map it as follows.

modelBuilder.Entity<Locale>()
            .HasMany(x => x.Localizations)
            .WithRequired(x => x.Locale)
            .Map(x => x.MapKey("LocaleId"));

This works, but then I need to map the entity itself. Doing this overrides the previous map.

modelBuilder.Entity<Locale>()
            .HasMany(x => x.Localizations)
            .WithRequired(x => x.Entity)
            .Map(x => x.MapKey("EntityId"));

Doing it this way throws an error on either field (I've also tried making a sub class of Localization called LocaleLocalization, with the same result).

 modelBuilder.Entity<Localization<Locale>>()
             .HasRequired(x => x.Entity)
             .WithMany()
             .Map(x => x.MapKey("LCIDLocale"))

The Error

The navigation property "Entity" is not a declared property on type Localization. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.

Paul Connolly
  • 359
  • 2
  • 8

1 Answers1

0

The solution is that I need to map two collections, one representing the collection of Localizations for this Locale, and one representing the collection of other Locales which are localized into this locale.

ICollection<Localizations> MyLocalizations { get; set; }
ICollection<Localizations> LocalesLocalizedByMe { get; set; }
Paul Connolly
  • 359
  • 2
  • 8