【发布时间】:2022-01-04 22:27:38
【问题描述】:
我无法获得 Navigation Prop. 1) 我可以在没有 Include() 的情况下完成它吗? 2)如何?似乎有几种方法。哪个最简单
我无法获得 Navigation Prop. 1) 我可以在没有 Include() 的情况下完成它吗? 2)如何?似乎有几种方法。哪个最简单
我无法获得 Navigation Prop. 1) 我可以在没有 Include() 的情况下完成它吗? 2)如何?似乎有几种方法。哪个最简单
我无法获得 Navigation Prop. 1) 我可以在没有 Include() 的情况下完成它吗? 2)如何?似乎有几种方法。哪个最简单
[Table("schools")]
public class School : BaseEntity<int>
{
public School()
{
Category = new Category();
District = new District();
}
[JsonIgnore]
[Column("category_id")]
[ForeignKey("Category")]
public short CategoryId { get; set; }
public Category Category { get; set; }
[JsonIgnore]
[Column("district_id")]
[ForeignKey("District")]
public int DistrictId { get; set; }
public District District { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("rating")]
public decimal Rating { get; set; }
[Column("vote_count")]
public int VoteCount { get; set; }
[Column("comment_count")]
public int CommentCount { get; set; }
[JsonIgnore]
public virtual IList<SchoolComment> SchoolComments { get; set; }
}
/////////////
[Table("comments")]
public class Comment : BaseEntity<int>
{
public Comment()
{
Commenter = new Commenter();
}
[JsonIgnore]
[Column("commenter_id")]
[ForeignKey("Commenter")]
public int CommenterId { get; set; }
public Commenter Commenter { get; set; }
[Column("text")]
public string Text { get; set; }
[Column("like_count")]
public int LikeCount { get; set; }
[Column("dislike_count")]
public int DislikeCount { get; set; }
[JsonIgnore]
[InverseProperty("Comment")]
public virtual IList<Reply> Replies { get; set; }
[JsonIgnore]
[InverseProperty("Comment")]
public virtual IList<SchoolComment> SchoolComments { get; set; }
}
////
[Table("school_comments")]
public class SchoolComment : BaseEntity<int>
{
public SchoolComment()
{
Comment = new Comment();
School = new School();
}
[JsonIgnore]
[Column("comment_id")]
[ForeignKey("Comment")]
public int CommentId { get; set; }
public Comment Comment { get; set; }
[JsonIgnore]
[Column("school_id")]
[ForeignKey("School")]
public int SchoolId { get; set; }
public School School { get; set; }
[Column("rating")]
public int Rating { get; set; }
[JsonIgnore]
[InverseProperty("SchoolComment")]
public virtual IList<Reply> Replies { get; set; }
}
////
public override List<SchoolComment> GetList(Func<SchoolComment, bool> filter = null)
{
using Context context = new Context();
return filter == null
? context.Set<SchoolComment>().Include(p => p.Comment).Include(p => p.School).ToList()
: context.Set<SchoolComment>().Include(p => p.Comment).Include(p => p.School).Where(filter).ToList();
}
```
*I couldn't get Navigation Prop. 1)Can I make it without Include(). 2) How? It seems there is a few way. Which is the easiest*
*I couldn't get Navigation Prop. 1)Can I make it without Include(). 2) How? It seems there is a few way. Which is the easiest*
*I couldn't get Navigation Prop. 1)Can I make it without Include(). 2) How? It seems there is a few way. Which is the easiest*
*I couldn't get Navigation Prop. 1)Can I make it without Include(). 2) How? It seems there is a few way. Which is the easiest*
【问题讨论】:
标签: c# .net postgresql entity-framework entity-framework-core