0
votes
 public class Slider_Locale
    {
        [Key]
        public int Slider_LocaleID { get; set; }

        [ForeignKey("Culture")]
        public int CultureID { get; set; }
        public string Slogan { get; set; }


        public virtual Culture Culture { get; set; }
    }

   public class Culture
    {
        [Key]
        public int CultureID { get; set; }
        public string CultureName { get; set; }
        public string DisplayName { get; set; }

        public virtual Slider_Locale slider_Locale { get; set; }
    }

It gives error as follows:

One or more validation errors were detected during model generation:

System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'Slider_Locale_Culture_Source' in relationship 'Slider_Locale_Culture'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be �*�.

How could I design the relationship?. Please help me as I am newbie in mvc and entity.

1

1 Answers

0
votes

This is one of those things that's a little tricky to wrap your brain around at first. The issue is that you're trying to set up a 1:1 (or 1:0) mapping, but there's nothing in your model to enforce that kind of mapping. For example, what if you have more than one Slider_Locale object with the same CultureID value? How would your application know which one to pick?

Now, you might know that this will never happen, but the Entity Framework doesn't, and it has to err on the side of caution, so it won't let you set up a relationship that it can't prove is consistent with the table structure. Ideally, it would let you specify unique constraints other than a primary key to work around this, and maybe someday it will, but for now the simplest way around this is to change it to a one-to-many mapping. For example, you could do:

public class Slider_Locale
{
  [Key]
  public int Slider_LocaleID { get; set; }

  [ForeignKey("Culture")]
  public int CultureID { get; set; }
  public string Slogan { get; set; }

  public virtual Culture Culture { get; set; }
}

public class Culture
{
  [Key]
  public int CultureID { get; set; }
  public string CultureName { get; set; }
  public string DisplayName { get; set; }

  // Note that this got changed to ICollection<>
  public virtual ICollection<Slider_Locale> slider_Locales { get; set; }
}

Another thing you could do is change the classes so that they share the same primary key values, but in order to do that you'll have to make at least one of the relationships optional. I could give an example of this if you let me know whether Slider_Locale.Culture can be null, or Culture.slider_Locale, or both.