使用MVC和Entity Framework在其他表的视图中访问外键表的属性

时间:2018-11-17 14:02:05

标签: sql-server asp.net-mvc entity-framework

我们如何从JobPostActivity访问Resume的属性    CandidateDetail?

//CandidateDetail

namespace CarrerPage
{
using System;
using System.Collections.Generic;

public partial class CandidateDetail
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", 
"CA2214:DoNotCallOverridableMethodsInConstructors")]
    public CandidateDetail()
    {
        this.JobPostActivitys = new HashSet<JobPostActivity>();
    }

    public int RID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string EmailID { get; set; }
    public string PHONENUMBER { get; set; }
    public int Experience { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", 
  "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<JobPostActivity> JobPostActivitys { get; set; 
}
}
}

//JobPostActivity
namespace CarrerPage
{
using System;
using System.Collections.Generic;

public partial class JobPostActivity
{
    public int Id { get; set; }
    public int RID { get; set; }
    public Nullable<int> CandidateID { get; set; }
    public Nullable<int> JobID { get; set; }
    public Nullable<System.DateTime> Applydate { get; set; }
    public string RESUME { get; set; }
    public byte[] FileContent { get; set; }

    public virtual CandidateDetail CandidateDetail { get; set; }
}
}

//Upload
  <div class="form-group">
    @Html.LabelFor(model=>model., htmlAttributes: new { 
 @class = "control-label col-md-2" })
    <div class="col-md-10">
        <input type="file" name="files" required />
        @Html.ValidationMessageFor(model=> model.)
    </div>
</div>

https://www.itsolutions-inc.com/news-and-training/article/entity-framework-6-database-first-versus-code-first/     在该模型附近,如何访问候选人详细信息中的Resume属性?

0 个答案:

没有答案