0
我的數據庫是使用代碼優先創建的。這是我的客戶的模型。從Linq的其他表中獲取具體信息
public int Id { get; set; }
[Required]
public string FirstName { get; set; }
[Display(Name = "Phone number")]
public int PhoneNumber { get; set; }
[Display(Name = "Email adress")]
[EmailAddress]
public string EmailAdress { get; set; }
[Display(Name = "Date of the wedding")]
public DateTime DateOfTheWedding { get; set; }
[Display(Name = "Type of client")]
public TypeOfClient TypeOfClient { get; set; }
[NotMapped]
public int DaySinceLastVisit { get; set; }
我也有一個模型訪問:
public int Id { get; set; }
public Client Client { get; set; }
[Required]
[ForeignKey("Client")]
public int ClientId { get; set; }
[Display(Name = "Date of the visit")]
public DateTime DateOfTheVisit { get; set; }
public String Comment { get; set; }
每個客戶端有多個訪問。 如何獲取上次訪問並將其添加到我的模型中?
這是我想要改進的resquest linq。
var clientsQueryable = _context.Clients
.Include(c => c.TypeOfClient);
if (!String.IsNullOrWhiteSpace(query))
clientsQueryable.Where(client => client.FirstName.Contains(query));
var listClients = clientsQueryable
.ToList()
.Select(Mapper.Map<Client, ClientDto>);
return Ok(listClients);
我想在客戶端的信息DaySinceLastVisit。 我認爲我們需要進行最後一次訪問並計算一下自此次訪問以來經過的日子。
此解決方案,感謝您的時間,我學到新的東西今天,偉大的! – ParkPark