CREATE TABLE [dbo].[test](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[ctext] [varchar](12) NOT NULL,
CONSTRAINT [PK_test] PRIMARY KEY CLUSTERED
(
[id] ASC
))
CREATE TABLE [dbo].[Comments](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[cComments] [varchar](250) NOT NULL,
[fk_test] [bigint] NOT NULL)
GO
ALTER TABLE [dbo].[Comments] WITH CHECK ADD CONSTRAINT [FK_Comments_test] FOREIGN KEY([fk_test])
REFERENCES [dbo].[test] ([id])
ON DELETE CASCADE
两个表以正常的一对多关系链接。
我想要一个返回列表列表的 Select:
-----------------------------------------------------
|test.id|test.cnumber|comments.id|comments.cComments|
|-------|------------|-----------|------------------|
| 1 | mytest1 | 1 | comment1 |
| | | 2 | comment2 |
| | | 3 | comment3 |
| | | 4 | comment4 |
| | | 5 | comment5 |
| | | 6 | comment6 |
| 2 | mytest2 | 7 | comment7 |
| | | 8 | comment8 |
| 3 | mytest3 | 7 | comment9 |
-----------------------------------------------------
有什么办法吗?
我试图用 sql 存储过程替换 linq。