多对多实体框架核心6(未生成交界表)
我刚刚开始使用 Entity Framework Core 6。 我正在使用一个示例数据库,其中存在多对多关系。
我在 SQL Server 上创建了数据库。我创建了三个表:Service、Document、ServiceDocs(用作连接表)。
然后我做了:
scaffolf-dbcontext
除了连接表 ServiceDocs 之外,两个类都已生成。 我的问题是:如何在没有连接表类的情况下向连接表添加元素并从中获取数据?
感谢您的帮助。
Class document:
public partial class Document
{
public Document()
{
Services = new HashSet<Service>();
}
public Guid DocumentId { get; set; }
public string? DocTitre { get; set; }
public virtual ICollection<Service> Services { get; set; }
}
public partial class Service
{
public Service()
{
Docs = new HashSet<Document>();
}
public Guid ServiceId { get; set; }
public string? Libelle { get; set; }
public virtual ICollection<Document> Docs { get; set; }
}
I've just started to work with Entity Framework Core 6.
I am working with a sample database where I have a many to many relationship.
I created my database on SQL server. I created three tables: Service, Document, ServiceDocs (used as a Junction Table).
Then I did :
scaffolf-dbcontext
both classes have been generated except the junction table ServiceDocs.
My question is: How can I add elements to the junction table and get data from it without the class of the junction table?
Thank you for your help.
Class document:
public partial class Document
{
public Document()
{
Services = new HashSet<Service>();
}
public Guid DocumentId { get; set; }
public string? DocTitre { get; set; }
public virtual ICollection<Service> Services { get; set; }
}
public partial class Service
{
public Service()
{
Docs = new HashSet<Document>();
}
public Guid ServiceId { get; set; }
public string? Libelle { get; set; }
public virtual ICollection<Document> Docs { get; set; }
}
Here some screenshots :
Database diagram
Document
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了如何获取数据的答案:
谢谢。
I found the answer how to get the data:
Thank you.