我正在建立一个假期跟踪网站。
我的mvc应用程序中有两个数据连接。
DeafultConnection,其中包含我用于用户登录和注册的aspnetusers。
然后使用LotusWorksEntities跟踪员工的详细信息,例如假期请求,工作时间等。
在aspnetusers下的DefaultConnections中,有一个电子邮件列。 在“员工表”下的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; }
}
员工表和站点表通过外键连接。
答案 0 :(得分:0)
不完全了解您所指的是数据库连接中的哪两个连接?
但是无论如何,您都可以使用Linq联接来连接C#中的两个单独的对象列表。过滤数据。基本上,您的两个列表应该与加入工作有关。
Here说明了如何在内存中加入两个列表。