Abood Alkreen Ответов: 1

Где ошибка при установке отношения один к одному


у меня есть класс буксировки при установке нового отношения один к одному
выдавать эту ошибку
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.


а это мой класс
Класс The_Sponsor :
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; }

    }
}


а это класс для посетителей:
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; }
       






    }
}


Что я уже пробовал:

я добавляю Api flutter вот так
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Visitor>()
      .HasRequired(s => s.sponsor)
      .WithRequiredPrincipal(ad => ad.visitor);

}

1 Ответов

Рейтинг:
0

Sinisa Hajnal

В одном у вас есть Sponsor_ID, в другом Sponsor_Id

C# чувствителен к регистру...