在EF中插入多对多表 [英] Insert into Many to Many tables in EF
本文介绍了在EF中插入多对多表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i有3张桌子:
1.Human
2.Club
3.HumanClub
HumanClubs包含:
idHuman
idClub
如何将记录插入HumanClub表?
Hi,
i have 3 tables :
1.Human
2.Club
3.HumanClub
that HumanClubs contains :
idHuman
idClub
How can i insert records into HumanClub table??
推荐答案
享受...
Enjoy...
create table Human(id int IDENTITY,SomeField varchar(50))
create table Club(id int IDENTITY,SomeField varchar(50))
create table HumanClub(id int IDENTITY,HumanId int, ClubId INT)
DECLARE @HumarId INT, @ClubId INT
INSERT INTO Human values('Some Human')
SET @HumarId = SCOPE_IDENTITY()
INSERT INTO Club values('Some Club')
SET @ClubId = SCOPE_IDENTITY()
INSERT INTO HumanClub values(@HumarId,@HumarId)
SELECT * FROM HumanClub
这篇关于在EF中插入多对多表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文