SubSonic 和自参考表
我们在使用 SubSonic 的 ActiveRecord 模板和自引用表时遇到一些问题。
我们有一个表“类别”,其中可以包含子类别。该表包含主键 (Id) 和外键 (ParentId)。
代码生成对于除此之外的所有其他关系都非常有效。
生成的代码是:
var repo= Category.GetRepo();
return from items in repo.GetAll()
where items.Id == _ParentId
select items;
它应该看起来像这样:
var repo= Category.GetRepo();
return from items in repo.GetAll()
where items.ParentId == _Id
select items;
数据库中的外键看起来像这样:
ALTER TABLE [dbo].[Category]
ADD CONSTRAINT [FK_Category_Category] FOREIGN KEY ([ParentId]) REFERENCES [dbo].[Category] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
我想使用模板来解决这个问题,而不是创建一个新的分部类。
我可以在模板文件中做一些修改来完成这项工作,但我真的很想知道我做错了什么:)。
谢谢 -罗宾
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 this 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论