Привет, я работаю над efcore. У меня есть таблица структуры, как показано ниже.
public class User
{
public User()
{
this.Projects = new HashSet<Project>();
}
[Key]
public int Id { get; set; }
public string name { get; set; }
public string emailId { get; set; }
public virtual ICollection<Project> Projects { get; set;}
}
public class Project
{
public Project()
{
this.TimeSheetData = new HashSet<TimeSheetData>();
}
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int userId { get; set; }
[ForeignKey("userId")]
public virtual User User {get; set; }
public virtual ICollection<TimeSheetData> TimeSheetData { get; set;}
}
public class TimeSheetData
{
[Key]
public int id { get; set; }
public int project_id { get; set; }
[ForeignKey("project_id")]
public virtual Project Project {get; set; }
public string hours_logged { get; set; }
}
Я пытаюсь получить TimeSheetData, как показано ниже.
public User GetTimeSheet(int userid)
{
return _context.Users.Include(u => u.Projects.Select(p => p.TimeSheetData)).Where(u => u.Id ==userid).FirstOrDefault();
}
, которые дают мне ошибку ниже.
The Include property lambda expression 'u => {from Project p in u.Projects select [p].TimeSheetData}' is invalid. The expression should represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, specify an explicitly typed lambda parameter of the target type, E.g. '(Derived d) => d.MyProperty'
I Я использовал указанные выше пространства имен в моем файле.
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TimeSheet.DataLayer;
using Microsoft.EntityFrameworkCore;
Может кто-нибудь помочь мне разобраться в этой проблеме. Любая помощь будет принята с благодарностью. Спасибо