如果列的单数名称与表名称相同,如何避免 SubSonic 3 中的错误?
抱歉,标题令人困惑,我不确定如何以不同的方式表达它......
好吧,问题是:
我有一个名为“Products”的表,主键是“Product”。通常,这不会导致任何问题。然而,我切换到 SubSonic 3,它使所有表格变得单一。因此,当我重建 T4 模板时,它会抛出错误,因为它将列重命名为“ProductX”,但不会更新其余代码。例如,会出现以下错误:
public IQueryable<Product> Products
{
get
{
var repo=AM.Inventory.Library.SonicData.Product.GetRepo();
return from items in repo.GetAll()
where items.Product == _Product
select items;
}
}
但是,如果我将其更改为:
public IQueryable<Product> Products
{
get
{
var repo=AM.Inventory.Library.SonicData.Product.GetRepo();
return from items in repo.GetAll()
where items.ProductX == _Product
select items;
}
}
代码将构建得很好。如果我必须这样做一两次,那很好......但每当我重建 T4 文件时,我都必须手动更新文件。
有什么办法可以避免这种情况吗?
谢谢, 安德鲁
Sorry for the confusing title, I wasn't sure how to word it any differently...
Ok, here's the issue:
I have a table named "Products" and the primary key is "Product". Normally, this doesn't cause any issues. However, I'm switching to SubSonic 3 and it makes all the tables singular. Thus, when I rebuild the T4 Templates it throws an error as it renamed the column to "ProductX" but doesn't update the rest of the code. For example, this errors out:
public IQueryable<Product> Products
{
get
{
var repo=AM.Inventory.Library.SonicData.Product.GetRepo();
return from items in repo.GetAll()
where items.Product == _Product
select items;
}
}
But, if I change it to:
public IQueryable<Product> Products
{
get
{
var repo=AM.Inventory.Library.SonicData.Product.GetRepo();
return from items in repo.GetAll()
where items.ProductX == _Product
select items;
}
}
The code will build just fine. If I had to do this once or twice, that's fine... but whenever I rebuild the T4 files I'd have to update the files manually.
Is there any way to avoid this?
Thanks,
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修改您的 T4 模板。这就是他们存在的目的。
在 ttinclude 中查找 MakeSingular()、MakePlural()、Cleanup(),添加“X”的代码位于 ActiveRecord.tt 中。破解他们!
实际上,这听起来像是命名代码中的一个错误,所以现在可能是通过消除该错误做出贡献的时候了。
Modify your T4 templates. That's what they're there for.
Look for MakeSingular(), MakePlural(), Cleanup() in the ttincludes, and the code that adds the "X" is in ActiveRecord.tt. Hack 'em!!!
Actually, it sounds like a bug in the naming code, so this might be the time for making a contribution by squashing the bug.