여러 인보이스 항목이있는 인보이스가 생성됩니다. 이 송장은 여러 송장 항목 모습입니다 : Linq - 시퀀스에 하나 이상의 요소가 포함되어 있습니다.
내가 전체 페이지 새로 고침을 수행 할 때, 그것은 휴식이 오류가 발생합니다 :
public ActionResult Create(long userId, long invoiceId)
{
ViewBag.InvoiceId = invoiceId;
ViewBag.UserId = userId;
ViewBag.UserId = userId;
var objInvoiceItems = (from i in db.tblinvoiceitems
where i.InvoiceId == invoiceId
select i
).ToList();
var a = (from o in objInvoiceItems
select new InvoiceItemViewModel {
Description = o.DESCRIPTION,
Quantity = o.Quantity,
Rate = o.Rate,
Id = o.ID,
InvoiceId = o.InvoiceId
}).ToList();
var objInvoice = (from i in db.tblinvoices
where i.ID == invoiceId
select i
).ToList();
var obj = (from i in objInvoice
join j in a
on i.ID equals j.InvoiceId
select new InvoiceCreateViewModel
{
AmountPaid = i.AmountPaid,
DueDate = i.DueDate,
InvoiceNo = i.ID,
UserId = i.UserId,
InvoiceItems = a
//InvoiceItems = j
}).SingleOrDefault();
//obj.InvoiceItems = ListInvoiceItems(invoiceId.ToString()).Model;
if (obj == null)
{
obj = new InvoiceCreateViewModel();
}
return View(obj);
}
public class InvoiceCreateViewModel
{
public long? UserId { get; set; }
public double? AmountPaid { get; set; }
public DateTime? DueDate { get; set; }
public double? TotalAmount { get; set; }
public long InvoiceNo { get; set; }
public double? Rate { get; set; }
public string Description { get; set; }
public int? Quantity { get; set; }
public IEnumerable<InvoiceItemViewModel> InvoiceItems { get; set; }
}
이 내 코드입니다
Sequence contains more than one element
을
라인이 깨지고 있습니다 (SingleOrDefault()
). 송장은 항상 하나이며 InvoiceItems는 여러 배가 될 수 있습니다. jquery를 통해 다른 함수에서 Add new Invoice Items
을 처리하고 있으므로이 함수는 송장 항목이없는 새 송장을 만들 때 한 번만 나타납니다.
여러 인보이스 항목으로 하나의 인보이스를 반환하고 싶습니다.
이를 모든 LINQ 쿼리 작업을 수행 할 수 있습니다 여러 개의 invoiceItem이있을 수 있기 때문에 데카르트 제품의 결과입니다. 당신이하고 싶은 것은'InvoiceItemViewModel'의 목록을 가지고있는'InvoiceCreateViewModel'을 가지고 있습니다 –
그래, 어떻게해야합니까? 내 invoicecreateviewmodel에, 나는의 ienumberable을 가지고있다. –
Baahubali