0

I am encountering an error to the effect of "A specified Include path is not valid. The EntityType 'MyCMS.DAL.SiteSettings' does not declare a navigation property with the name 'SiteSettingOptions'."

I have read quite a few posts about this issue but all of the research I have done pertains to ICollections and not for properties that are classes.

Here is where I am and could use your help resolving the issues.

[Table("SiteSettingsBridge")]
[DataContract]
public partial class SiteSettings
{
    [Key]
    [DataMember]
    public int SiteSettingsBridgeID { get; set; }

    [DataMember]
    public int SiteID { get; set; }

    [DataMember]
    public int SiteSettingOptionID { get; set; }

    [DataMember]
    public virtual SiteSettingOptions SiteSettingOption { get; set; }

    [DataMember]
    [StringLength(500)]
    public string Value { get; set; }

    public SiteSettings()
    {
        SiteSettingsBridgeID = 0;
        SiteID = 0;
        SiteSettingOptionID = 0;
        Value = "";
    }
}



[DataContract]
public partial class SiteSettingOptions
{
    [Key]
    [DataMember]
    public int SiteSettingOptionID { get; set; }

    [DataMember]
    public string SettingsGroup { get; set; }

    [DataMember]
    [StringLength(100)]
    public string Name { get; set; }

    [DataMember]
    [StringLength(500)]
    public string DefaultValue { get; set; }

    [DataMember]
    public SettingType Type { get; set; }

    public enum SettingType
    {
        String = 1,
        Bool = 2,
        Integer = 3
    }

    public SiteSettingOptions()
    {
        SiteSettingOptionID = 0;
        SettingsGroup = string.Empty;
        Name = string.Empty;
        DefaultValue = string.Empty;
        Type = SiteSettingOptions.SettingType.String;
    }
}

and then in my DAL project, I am attempting to add an Include to the context query like this

public static List<Contracts.Sites.SiteSettings> GetBySiteID(int SiteID)
{
 using (CMSContext cntx = new CMSContext())
 {
    ///OMITTED FOR BREVITY

    return cntx.SiteSettings.Include("SiteSettingOptions").Where(i => i.SiteID == SiteID).ToList();

 }
}

When I compile and run, I am receiving the above error.

To answer a few questions up front, I am not using LazyLoading and I am not doing anything on model create.

Yes, I am brand new to EF. This is my first app.

Solo812
  • 401
  • 1
  • 8
  • 19
  • 3
    Your property is called `SiteSettingOption` (no s) but you are trying to `Include("SiteSettingOptions")` (notice the final s). Remove the last s. You can avoid this by using the Include extension that uses lambdas rather than strings this would be something like `Include(x => x.SiteSettingOption)`. – Ben Robinson Nov 25 '14 at 16:21
  • Thank you so much. I was mistakenly under the impression that the string inside of the quotes was pointing to a table in the database. As a side note, I cannot use the lambda anywhere in the DAL project. I am not sure why. I get a compile error of "Cannot convert lambda expression to type string". I have seen this posted everywhere but it hasn't worked for me. – Solo812 Nov 25 '14 at 16:28
  • For whatever reason the lambda based `Include` is an extension method in a different class in a different namespace. You need to add `using System.Data.Entity` to be able to use it. – Ben Robinson Nov 25 '14 at 16:31
  • Ben...you rock! Thank's again for your help. – Solo812 Nov 25 '14 at 16:36

1 Answers1

0

Thanks Ben...

Your property is called SiteSettingOption (no s) but you are trying to Include("SiteSettingOptions") (notice the final s). Remove the last s. You can avoid this by using the Include extension that uses lambdas rather than strings this would be something like Include(x => x.SiteSettingOption)

reggaeguitar
  • 1,795
  • 1
  • 27
  • 48
Solo812
  • 401
  • 1
  • 8
  • 19