[英]how to get a list of item in object from another table using linq and entity framework in C#?
Below is the following code that i am using. 以下是我正在使用的以下代码。 i am getting error as shown in attached screenshot. 如附件屏幕截图所示,我遇到了错误。
public class BioHazardAffectedPropertyDetails
{
public int BiohazardID { get; set; }
public string WONumber { get; set; }
public string BiohazardName { get; set; }
public string PropertyAddress { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public string Signature { get; set; }
public Nullable<System.DateTime> Date { get; set; }
public IEnumerable<FormItem> formItemList { get; set; }
}
public Response Get(string wOrder) { Response res = new Response(); 公共响应Get(字符串wOrder){响应res =新的Response();
if (string.IsNullOrEmpty(wOrder))
throw new ArgumentNullException(wOrder);
try
{
using (HoarderDBEntities db = new HoarderDBEntities())
{
List<HoarderApi.Models.BiohazardForm> oBiohazardForm = new List<HoarderApi.Models.BiohazardForm>();
List<HoarderApi.Models.FormItem> objForm = new List<HoarderApi.Models.FormItem>();
var bioH = from ob in db.BiohazardForms
join fi in db.FormItems on ob.WONumber equals fi.WONumber
where ob.WONumber == fi.WONumber
select new BioHazardAffectedPropertyDetails
{
BiohazardName = ob.BiohazardName,
PropertyAddress = ob.PropertyAddress,
Date = ob.Date,
Phone = ob.Phone,
Address = ob.Address,
Name = ob.Name,
Signature = ob.Signature,
formItemList = db.FormItems.Where(x => x.WONumber == ob.WONumber).ToList<FormItem>()
};
//foreach (FormItem fii in oFI)
//{
// bioH = obioHForm.Zip(oFI, (obiohform, ofi) => new { obiohform.BiohazardName, obiohform.PropertyAddress, obiohform.Date, obiohform.Phone, obiohform.Name, obiohform.Signature, fii.ItemsID, fii.ItemDesc, fii.Quantity, fii.IfKept, fii.Initial, fii.IsBiohazard }).ToList();
//}
//res.status.success = true;
//[![enter image description here][1]][1]res.data = bioH;
}
}
catch (Exception ex)
{
res = new Response(ex);
}
return res;
}
what i am trying to do is that i want to fetch detail from another table which has multiple rows having data related to wOrder and return it to the list type object formItemList. 我想做的是,我想从另一个表中获取详细信息,该表具有多行包含与wOrder相关的数据,并将其返回到列表类型对象formItemList。 but when it executes the following code then it is return the following error in the image attached.can anyone simplify this or help me. 但是当它执行以下代码时,它将在所附的图像中返回以下错误。任何人都可以简化此过程或为我提供帮助。
Try this : 尝试这个 :
var bioH = from ob in db.BiohazardForms
join fi in db.FormItems on ob.WONumber equals fi.WONumber into g
select new BioHazardAffectedPropertyDetails
{
BiohazardName = ob.BiohazardName,
PropertyAddress = ob.PropertyAddress,
Date = ob.Date,
Phone = ob.Phone,
Address = ob.Address,
Name = ob.Name,
Signature = ob.Signature,
formItemList = g
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.