0

我正在建立一个假期跟踪网站。

我的 mvc 应用程序中有两个数据连接。

DeafultConnection 包含我用于用户登录和注册的 aspnetusers。

然后是我用来跟踪员工详细信息的 LotusWorksEntities,例如假期请求、工作时间等。

在 aspnetusers 下的 DefaultConnections 中,有一列用于电子邮件。在 Employee Table 下的 LotusWorksEntitles 中,还有一个电子邮件列。

在我的管理员视图页面上,我有一个包含站点列的所有员工的列表。

我希望已分配到某些站点的管理员只能查看那些已分配站点的员工。

我已经手动完成了

public ActionResult Index()
    {

        var employees = db.Employees.Include(e => e.Area).Include(e => e.Discipline).Include(e => e.Shift).Include(e => e.Site).Where(e => e.SiteID == 2);
        return View(employees.ToList());
    } 

有没有办法可以连接这两个连接,这样当管理员登录时,它知道他们被分配到哪个站点并在该站点下显示这些员工。

这是我的模型:

 public partial class Employee
{
    public int EmployeeID { get; set; }
    public string FullName { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public System.DateTime StartDate { get; set; }
    public int RoleID { get; set; }
    public int ShiftID { get; set; }
    public int AreaID { get; set; }
    public int DisciplineID { get; set; }
    public int SiteID { get; set; }
    public int ALCategory { get; set; }
    public int HoursTaken { get; set; }
    public Nullable<int> AwardedLeave { get; set; }
    public Nullable<int> TotalHoursThisYear { get; set; }
    public int HoursCarriedForward { get; set; }
    public Nullable<int> EntitlementRemainingThisYear { get; set; }
    public string Comments { get; set; }
    public int SickLeaveTaken { get; set; }
    public Nullable<int> SickLeaveEntitlement { get; set; }
    public Nullable<int> SickLeaveEntitlementRemaining { get; set; }
    public int StudyLeaveEntitlement { get; set; }
    public int StudyLeaveTaken { get; set; }
    public Nullable<int> StudyLeaveRemaining { get; set; }
    public int ExamLeaveTaken { get; set; }
    public int ForceMajeure { get; set; }
    public int BereavementLeaveTaken { get; set; }
    public int MaternityLeaveTaken { get; set; }
    public int ParentalLeaveTaken { get; set; }
    public int AdoptionLeaveTaken { get; set; }
    public string ManagerEmail { get; set; }
    public string AreaManagerEmail { get; set; }

    public virtual Area Area { get; set; }
    public virtual Discipline Discipline { get; set; }
    public virtual Shift Shift { get; set; }
    public virtual Site Site { get; set; }
}

然后我的站点模型是:

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

    public int SiteID { get; set; }
    public string SiteName { get; set; }
    public string SiteManager { get; set; }
    public string SiteDelegate { get; set; }
    public string SiteAdmin { get; set; }
    public string SiteLocation { get; set; }

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

员工表和站点表通过外键连接。

4

1 回答 1

0

不完全明白你有哪两个连接是你在谈论的数据库连接?

但无论如何,您可以使用 Linq 连接来连接 C# 中的两个单独的对象列表。过滤数据。基本上,您的两个列表应该与加入工作有一些关系。

这里解释了如何在内存中加入两个列表。

于 2019-01-21T12:30:57.100 回答