Click here to Skip to main content
15,442,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have tow class when set new relation one to one
display this error
The ForeignKeyAttribute on property 'V_ID' on type 'adminSection.Models.The_Sponsor' is not valid. The navigation property 'Visitor' was not found on the dependent type 'adminSection.Models.The_Sponsor'. The Name value should be a valid navigation property name.


and this is my class
The_Sponsor class :
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace adminSection.Models
{
    [Table("The_Sponsor")]
    public partial class The_Sponsor
    {
        //[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        //[ForeignKey("Visitor")]
        [Key]
        public int Sponsor_Id { get; set; }
        [Required(ErrorMessage = "you ust provide full name")]
        [Display(Name = "Full Name")]
        public string Sponsor_FullName { get; set; }

        [Required(ErrorMessage = "you must provied phone number")]
        [Display(Name = "Phone Number")]
        [DataType(DataType.PhoneNumber)]
        public string Sponsor_Phone { get; set; }

        [Required(ErrorMessage = "You must provide Email Address")]
        [Display(Name = "Email Address")]
        [DataType(DataType.EmailAddress)]
        public string Sponsor_Email { get; set; }

        [Required(ErrorMessage = "You must provide Password")]
        [Display(Name = "Password")]
        [DataType(DataType.Password)]
        public string Sponsor_Password { get; set; }
        [Required(ErrorMessage = "you must provide Location")]
        [Display(Name = "You must provide Location")]
        public string Sponsor_Location { get; set; }

        [Required(ErrorMessage = "You provide image path")]
        [Display(Name = "image path")]
        public string Sponsor_Image_Path { get; set; }

        public string User_Type{ get; set; }

        [ForeignKey("Visitor")]
        public int V_ID { get; set; }
        public virtual Visitor visitor { get; set; }

        public virtual Minsitry min { get; set; }
        public int Min_id { get; set; }

    }
}


and this is Visitor class:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace adminSection.Models
{
    [Table("tbl_Visitor")]
    public partial class Visitor
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Key]
        
        public int Visitro_ID { get; set; }
        /// <summary>
        /// ID Att Section
        /// Section success
        /// </summary>

        [Required(ErrorMessage ="you must provide your full name")]
        [Display(Name ="Full Name")]
        public string Visitor_FullName { get; set; }
        /// <summary>
        /// Full Name Att Section
        /// Section success
        /// </summary>
        /// 

        [Required(ErrorMessage ="You must provide your Email")]
        [Display(Name ="Email Address")]
        [DataType(DataType.EmailAddress)]
        public string Visitor_Email { get; set; }
        /// <summary>
        /// Email Address Att Section
        /// section success
        /// </summary>
        /// 
        [Required(ErrorMessage ="you must provide password")]
        [Display(Name ="Password")]
        [DataType(DataType.Password)]
        public string  Visitor_Password { get; set; }
        /// <summary>
        /// Password Att Section
        /// section success
        /// </summary>
        /// 
        [Required(ErrorMessage ="you must provide phone number")]
        [Display(Name ="Phone Number")]
        [DataType(DataType.PhoneNumber)]
        public int Visitor_Phone { get; set; }
        /// <summary>
        /// Phone Number Att Section
        /// Section success
        /// </summary>

        [Required(ErrorMessage ="you must upload your Image")]
        [Display(Name ="upload Image")]
        public string  Visitor_Image_Path { get; set; }
        /// <summary>
        /// Image Path Att Section
        /// Section success
        /// </summary>

        public string User_Type { get; set; }
        /// <summary>
        /// User type Section
        /// Section success
        /// </summary>
        /// 

        public virtual ICollection<volunteer> volunterr { get; set; }
        /// <summary>
        /// Visior with volunteer has relation one to many
        /// section success
        /// sectioin success
        /// </summary>
        /// 

        
        public int Sponsor_ID { get; set; }
        
        public virtual The_Sponsor sponsor { get; set; }
       






    }
}


What I have tried:

i am adding Api flutter like this
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Visitor>()
      .HasRequired(s => s.sponsor)
      .WithRequiredPrincipal(ad => ad.visitor);

}
Posted
Updated 28-Apr-20 21:59pm

1 solution

In one you have Sponsor_ID in the other Sponsor_Id

C# is case sensitive...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900