Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架访问include和.thenClude中的数据_C#_Entity Framework_Entity Framework 6_Entity - Fatal编程技术网

C# 实体框架访问include和.thenClude中的数据

C# 实体框架访问include和.thenClude中的数据,c#,entity-framework,entity-framework-6,entity,C#,Entity Framework,Entity Framework 6,Entity,我不熟悉实体框架 我了解基本知识,但这里有点困惑 await Context.PremiseContacts .Include(c => c.Contact) .ThenInclude(c => c.ContactEmails) 假设我有这个代码 联系人在premise contacts中,然后联系人电子邮件在Contact中 我如何访问联系人电子邮件数据 我试过这个 Email = c.Contact.ContactEmails

我不熟悉实体框架

我了解基本知识,但这里有点困惑

await Context.PremiseContacts
             .Include(c => c.Contact)
             .ThenInclude(c => c.ContactEmails)
假设我有这个代码

联系人在premise contacts中,然后联系人电子邮件在Contact中

我如何访问联系人电子邮件数据

我试过这个

Email = c.Contact.ContactEmails.,
当传递模型时,但这是我得到的很多选项,并且联系人电子邮件中应该有更多属性

基本上,您如何访问由.include定义的数据,然后如何访问由多个include/then include定义的数据

编辑

前提接触

namespace SolaceSecure.DAL.Models
{
    [Table("premiseContact")]
    public partial class PremiseContact
    {
        [Key]
        [Column("premiseId")]
        public Guid PremiseId { get; set; }
        [Key]
        [Column("contactId")]
        public Guid ContactId { get; set; }
        [Column("isSolaceUser")]
        public bool? IsSolaceUser { get; set; }

        public virtual Contact Contact { get; set; }
        public virtual Premise Premise { get; set; }
    }
}
接触

  public Contact()
        {
            ContactEmails = new HashSet<ContactEmail>();
            ContactPhoneNumbers = new HashSet<ContactPhoneNumber>();
            PremiseComplianceContacts = new HashSet<PremiseComplianceContact>();
            PremiseContacts = new HashSet<PremiseContact>();
        }

        [Key]
        [Column("contactId")]
        public Guid ContactId { get; set; }
        [Required]
        [Column("contactName")]
        [StringLength(100)]
        public string ContactName { get; set; }
        [Column("contactDescription")]
        [StringLength(250)]
        public string ContactDescription { get; set; }
        [Column("customerId")]
        public Guid CustomerId { get; set; }
        [Column("userId")]
        public Guid? UserId { get; set; }
        [Column("dateCreated", TypeName = "datetime")]
        public DateTime DateCreated { get; set; }
        [Column("dateModified", TypeName = "datetime")]
        public DateTime? DateModified { get; set; }
        [Column("modifiedBy")]
        public Guid? ModifiedBy { get; set; }
        [Column("isDeleted")]
        public bool IsDeleted { get; set; }
        [Column("createdBy")]
        public Guid? CreatedBy { get; set; }

        public virtual Person CreatedByNavigation { get; set; }
        public virtual Customer Customer { get; set; }
        public virtual Person ModifiedByNavigation { get; set; }
        public virtual Person User { get; set; }
        public virtual ICollection<ContactEmail> ContactEmails { get; set; }
        public virtual ICollection<ContactPhoneNumber> ContactPhoneNumbers { get; set; }
        public virtual ICollection<PremiseComplianceContact> PremiseComplianceContacts { get; set; }
        public virtual ICollection<PremiseContact> PremiseContacts { get; set; }

您还没有告诉我们,但它看起来像是
c.Contact.ContactEmails
将为您提供一组电子邮件对象,因此您不能像这样将其分配给
email
变量。你需要决定当你有多封联系人电子邮件时会发生什么。向我们展示class
PremiseContact
-我们看不到你的屏幕,无法神奇地阅读你的代码-你需要向我们展示相关的位(更新:),所以我希望能够访问联系人电子邮件中的所有属性,因为电子邮件只是一个字符串。
c
是一个字符串吗
PremiseContact
还是收藏?
{
    [Table("contactEmail")]
    public partial class ContactEmail
    {
        [Key]
        [Column("contactEmailId")]
        public Guid ContactEmailId { get; set; }
        [Required]
        [Column("email")]
        [StringLength(100)]
        public string Email { get; set; }
        [Column("contactId")]
        public Guid ContactId { get; set; }
        [Column("emailTypeId")]
        public Guid EmailTypeId { get; set; }

        public virtual Contact Contact { get; set; }
    }
}