Уважаемые
У меня есть следующий код, и он должен показывать все записи, включенные подрядчики и reportsourcesC, но этот код показывает только те записи, которые соответствуют этим двум таблицам, но если нет соответствия, записине покажет, даже что я использовал DefaultIfEmpty ();следовательно, в чем может быть проблема.
Примечание. Таблица InjuresConseqs будет объединена со следующими таблицами AccidentCategory (обязательные данные) События (необязательные данные и нет проблем с этой таблицей) InjuryTypes (обязательные данные) PartOfBodys (обязательные данные), подрядчики (необязательные данные и данные).проблема с этой таблицей) reportsourcesC (необязательные данные и проблема с этой таблицей) EmploymentCats (обязательные данные) сдвиги (необязательные данные и проблемы с этой таблицей)
public List<ViweInjuresConseq> GetAllInjuresConseq(int ID= 0)
{
var data = (from FInjures in db.InjuresConseqs
join AccCat in db.AccidentCategory on FInjures.AccidentCategoryID equals AccCat.AccidentCategoryID
join Evnts in db.Events on FInjures.EventID equals Evnts.EventID into Eventresult
from Evnts in Eventresult.DefaultIfEmpty()
join InjType in db.InjuryTypes on FInjures.InjuryTypeID equals InjType.InjuryTypeID
join Partbody in db.PartOfBodys on FInjures.PartOfBodyID equals Partbody.PartOfBodyID
join contr in db.contractors on FInjures.Contractor_ID equals contr.Contractor_ID into contrresult
from contr in contrresult.DefaultIfEmpty()
join Report3 in db.reportsourcesC on FInjures.Reportsource3_ID equals Report3.Reportsource3_ID into Report3result
from Report3 in Report3result.DefaultIfEmpty()
join report2 in db.reportsourcesB on Report3.Reportsource2_ID equals report2.Reportsource2_ID into Report2result
from report2 in Report2result.DefaultIfEmpty()
join report1 in db.reportsourcesA on report2.Reportsource1_ID equals report1.Reportsource1_ID into Report1result
from report1 in Report1result.DefaultIfEmpty()
join Empcat in db.EmploymentCats on FInjures.EmploymentCatID equals Empcat.EmploymentCatID
join Shfts in db.Shifts on FInjures.ShiftID equals Shfts.ShiftID into Shftsresult
from Shfts in Shftsresult.DefaultIfEmpty()
select new ViweInjuresConseq
{
InjureID = FInjures.InjureID,
IN_ID = FInjures.IN_ID,
AccidentCategoryID = FInjures.AccidentCategoryID,
AccidentCategoryLabel = AccCat.AccidentCategoryD,
EventID = FInjures.EventID,
EventLabel = Evnts.EventD,
InjuryTypeID = FInjures.InjuryTypeID,
InjuryTypeLabel = InjType.InjuryTypeD,
InjuryTypeDes = FInjures.InjuryTypeDes,
PartOfBodyID = FInjures.PartOfBodyID,
PartOfBodyLabel = Partbody.PartOfBodyD,
PartOfBodyDes = FInjures.PartOfBodyDes,
authorities = FInjures.authorities,
EstmatedLWDC = FInjures.EstmatedLWDC,
ActualLWDC = FInjures.ActualLWDC,
Contractor_ID = FInjures.Contractor_ID,
ContractorLabel = contr == null ? string.Empty : contr.Contractor_Name,
Contractors = FInjures.Contractors,
Reportsource3_ID = FInjures.Reportsource3_ID,
Reportsource3Label = Report3 == null ? string.Empty : report1.Reportsource1 +"-"+ report2.Reportsource2 +"-"+ Report3.Reportsource3,
EmploymentCatID = FInjures.EmploymentCatID,
EmploymentCatLabel = Empcat.EmploymentCatDes,
Postion = FInjures.Postion,
ShiftID = FInjures.ShiftID,
ShiftLabel = Shfts.ShiftD,
DayOnTask = FInjures.DayOnTask,
ExInPosition = FInjures.ExInPosition,
ExOnTask = FInjures.ExOnTask,
EmID = FInjures.EmID,
FullName = FInjures.FullName,
Phone = FInjures.Phone,
Address = FInjures.Address,
comment = FInjures.comment
}).Where(a => a.IN_ID == ID).OrderBy(a => a.InjureID).ToList();
return (data);
}
Я поставилследующий код в DbContext для возможности миграции этих двух таблиц;потому что я столкнулся с проблемой во время миграции;это может быть проблемой
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Reportsources.ReportsourceC>().HasMany(p => p.ActionData).WithRequired(a=>a.ReportsourcesC).HasForeignKey(a=>a.Reportsource3_ID).WillCascadeOnDelete(false);
modelBuilder.Entity<Reportsources.ReportsourceC>().HasMany(p => p.InjuresConseq).WithRequired(a => a.ReportsourceC).HasForeignKey(a => a.Reportsource3_ID).WillCascadeOnDelete(false);
modelBuilder.Entity<Attached.Contractor>().HasMany(a => a.InjuresConseq).WithRequired(b => b.Contractor).HasForeignKey(a => a.Contractor_ID).WillCascadeOnDelete(false);
modelBuilder.Entity<Attached.Contractor>().HasMany(a => a.ContractorInvolve).WithRequired(b => b.Contractor).HasForeignKey(a => a.Contractor_ID).WillCascadeOnDelete(false);
}