开发者

SubSonic and self-referencing table

We are having some problems with SubSonic's ActiveRecord template and a self-referencing table.

We have a table, Category, that can contain sub-categories. The table contains a primary key (Id) and a foreign key (ParentId).

The code generation is working great with all other relationships except thi开发者_如何学运维s one.

The code generated is:

var repo= Category.GetRepo();
              return from items in repo.GetAll()
                   where items.Id == _ParentId
                   select items;

And it should look like this:

var repo= Category.GetRepo();
              return from items in repo.GetAll()
                   where items.ParentId == _Id
                   select items;

The foreign key in the database looks like this:

ALTER TABLE [dbo].[Category]
ADD CONSTRAINT [FK_Category_Category] FOREIGN KEY ([ParentId]) REFERENCES [dbo].[Category] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION;

I would like to solve this using the template rather than creating a new partial class.

I could do some hack in the template file to make this work but I really would like to know what I have done wrong :).

Thanks -Robin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜