Не удается преобразовать из system.datetime в long in ASP.NET ядро 3
<pre><big><pre>First in the database for time, I chose Big Int, but then I changed it to Small Data Time.
public async Task<IActionResult> Create(int? id, int? type) { if (id == null || type == null) { return NotFound(); } InsuranceViewModel model = null; ViewBag.Type = type; var companies = await _context.InsuranceCompany .Where(e => e.IsActice) .ToListAsync(); ViewData["CompanyList"] = new SelectList(companies, "Id", "CompanyName"); if ((InsuranceType)type == InsuranceType.Body) { var lastBody = _context.BodyInsurance .Where(e => e.VehicleInformationId == id.Value) .AsEnumerable() .LastOrDefault(); model = new InsuranceViewModel { InsuranceType = InsuranceType.Body, InsuranceNumber = "", IssueDate = lastBody != null ? new DateTime(lastBody.ExpireDate).AddDays(1) : DateTime.Today, ExpireDate = lastBody != null ? new DateTime(lastBody.ExpireDate).AddYears(1) : DateTime.Today.AddYears(1), VehicleInformationId = id.Value }; } else if ((InsuranceType)type == InsuranceType.Thirdpart) { var lastThirdParty = _context.ThirdPartyInsurance .Where(e => e.VehicleInformationId == id.Value) .AsEnumerable() .LastOrDefault(); var thirdParty = await _context.ThirdPartyInsurance .Include(e => e.InsuranceCompany) .FirstOrDefaultAsync(e => e.Id == id.Value); model = new InsuranceViewModel { InsuranceType = InsuranceType.Thirdpart, InsuranceNumber = "", IssueDate = lastThirdParty != null ? new DateTime(lastThirdParty.ExpireDate).AddDays(1) : DateTime.Today.Ticks, ExpireDate = lastThirdParty != null ? new DateTime(lastThirdParty.ExpireDate).AddYears(1) : DateTime.Today.AddYears(1), VehicleInformationId = id.Value }; } return View(model); }
Что я уже пробовал:
var lastThirdParty = await _context.ThirdPartyInsurance.Include(e => e.InsuranceCompany) .Where(e => e.VehicleInformationId == id) .OrderBy(e => e.ExpireDate) .LastOrDefaultAsync(); var lastBody = await _context.BodyInsurance.Include(e => e.InsuranceCompany) .Where(e => e.VehicleInformationId == id) .OrderBy(e => e.ExpireDate) .LastOrDefaultAsync();
The error is on this line: ? new DateTime(lastBody.ExpireDate).AddDays(1) lastBody.ExpireDate ----- cannot convert from system.datetime to long