1


Suppose I have the table Profiles that relates to my entity Profile

[Table("Profiles")]
public class Profile: BaseBusinessEntity {
   // Foreign key to the 'Members' table
   // one-to-one relation
   public int MemberId{
        get; 
        set; 
    }


    public DateTime? DateOfBirth{
        get; 
        set; 
    }

    #region === GEO PROPERTIES ===

    public int? CountryId{
        get; 
        set; 
    }

    public int? RegionStateId{
        get; 
        set; 
    }

    public int? CityId{
        get; 
        set; 
    }

    public int? ReligionId{
        get; 
        set; 
    }

    public int? OrientationId{
        get; 
        set; 
    }

    #endregion

    public virtual Members.Member Member{
        get; 
        set; 
    }

    public virtual City City{
        get; 
        set; 
    }

    public virtual Country Country{
        get; 
        set; 
    }

    public virtual RegionState RegionState{
        get; 
        set; 
    }

    public virtual ProfileMap ProfileMap{
        get; 
        set; 
    }  
}

I have issues with the properties 'OrientationId' and 'ReligionId' . They should be the foreign keys to the tables 'Orientations' and 'Religions' respectively, but I don't want to create the table 'Religions' just to hold several values (Christianity, Islam, Buddhism, Hindu) or the 'Orientations' table with only three values (Straight, Homosexual, Bisexual)

I plan to avoid this by creating table 'ProfileAttributes'and 'ProfileAttributeValues' and have the orientations saved as the profile attribute named 'Orientation' with predefined values in the 'ProfileAttributeValues' and have the religions saved as the profile attribute named 'Religion' with predefined values in the 'ProfileAtributeValues' table.

 [Table("ProfileAttributes")]
 public class ProfileAttribute : BaseLookupEntity {

   public ProfileAttribute(){
        HasMultipleValues = false;
    }

    public bool HasMultipleValues{
        get; 
        set; 
    }

    public virtual IList<ProfileAttributeValue> Values{
        get; 
        set; 
    } 
}


[Table("ProfileAttributeValues")]
public class ProfileAttributeValue : BaseBusinessEntity {

    public int Id{
        get; 
        set; 
    }

    public int ProfileAttributeId{
        get; 
        set; 
    }

    public int TypeId{
        get; 
        set; 
    }


    public int? IntValue{
        get; 
        set; 
    }

    public string CharValue{
        get; 
        set; 
    }

    public string StringValue{
        get; 
        set; 
    }

    public string String100Value{
        get; 
        set; 
    }

    public byte[] BinaryValue{
        get; 
        set; 
    }

    [NotMapped]
    public ProfileAttributeValueType Type{
        get{
            return (ProfileAttributeValueType) TypeId;
        }
    }

    public virtual ProfileAttribute ProfileAttribute{
        get; 
        set; 
    }
}

Now I need to somehow make the 'OrientationId' and 'ReligionId' properties as foreign keys referencing the 'ProfileAttributeValues' table. I mean to create a constraint that will allow only those IDs that exist in the 'ProfileAttributeValues' using Fluent API from EF .

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.