SubSonic 3 ActiveRecord 问题 - 空白数据
当我检查我的业务实体之一的 .Columns 属性时,我缺少 Table 和 PropertyName 的值。我从像 Take(5) 这样的东西中得到了正确的记录数,但是所有 5 个对象都将充满空字符串和 0 值。
刚刚尝试了另一个 SQL 连接,结果是一样的吗?我应该从哪里开始解决这个问题?
其他信息和代码:
// Replacing the CleanUp function seems to be cause
// What am I doing here that is not allowed?
// I'm dealing with Table names like USER_DETAILS and would prefer UserDetail
// rename standard CleanUp to CleanUp2 then paste this into Settings.ttinclude
string CleanUp(string tableName)
{
string res = tableName;
//capitalization
char[] ca = res.ToLower().ToCharArray();
for (int i = 0; i < ca.Length; i++) {
if ((i == 0) || (ca[i - 1] == '_')) {
ca[i] = char.ToUpper(ca[i]);
}
}
res = new string(ca);
//strip underlines
res = res.Replace("_","");
//strip blanks
res = res.Replace(" ","");
return res;
}
已解决(某种程度上): 看起来正是删除下划线导致一切都向南发展。罗布,这有可能在以后的版本中起作用吗?如果您能在源代码中为我指明正确的方向,我将很乐意提供帮助。
When I examine the .Columns property of one of my business entities I had missing values for Table and PropertyName. I get the right count of records back from things like Take(5) but all 5 objects will be full of empty strings and 0 values.
Just tried it with another SQL connection and same thing? Where should I start troubleshooting this?
ADDITIONAL INFO and CODE:
// Replacing the CleanUp function seems to be cause
// What am I doing here that is not allowed?
// I'm dealing with Table names like USER_DETAILS and would prefer UserDetail
// rename standard CleanUp to CleanUp2 then paste this into Settings.ttinclude
string CleanUp(string tableName)
{
string res = tableName;
//capitalization
char[] ca = res.ToLower().ToCharArray();
for (int i = 0; i < ca.Length; i++) {
if ((i == 0) || (ca[i - 1] == '_')) {
ca[i] = char.ToUpper(ca[i]);
}
}
res = new string(ca);
//strip underlines
res = res.Replace("_","");
//strip blanks
res = res.Replace(" ","");
return res;
}
SOLVED (sort of):
Looks like it is the removal of the underlines that causes everything to go south. Rob, any chance this could work in a later version? I'd be glad to help if you could point me in the right direction in the source.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您可以为您的一个表发布 CREATE sql - 这将是一种开始的方式。另外 - 确保你有主键等。
If you can post your CREATE sql for one of your tables - that would be a way to get started. Also - make sure you have primary keys, etc.
请注意,我认为这与我上周遇到的问题 #107 相同。
http://github.com/subsonic/SubSonic-3.0/issues#issue/ 107
Just to note, I think this is the same as issue #107 that I ran into last week.
http://github.com/subsonic/SubSonic-3.0/issues#issue/107
我刚刚在我的 SubSonic3 模板中应用了您的 CleanUp 功能。它工作得很好。但在此之前,我在 Subsonic Core 中制作了一些补丁,以便在 Subsonic 对象和表列之间进行通信。
QueryCommand 对象知道哪个
将投影的列(ExecutionBuilder.cs - 第 233 行)
您可以在此处查看我正在做的详细信息。
I've just applied your CleanUp function within my SubSonic3 Templates. It works just fine. But before do that, I made some patches within Subsonic Core to communicate between Subsonic objects and table column.
the QueryCommand object knows which
column that will be projected (ExecutionBuilder.cs - line 233)
You can look details what I'm doin in here.
在运行完代码库后,我想我已经找到了一个更简单的解决方案(恕我直言)。
IColumn 接口定义了一个“PropertyName”属性,我相信该属性旨在指示表示表类上此列的属性名称(类似于 ITable 上的“ClassName”属性)。在 Structs.tt 模板中,未设置此值,因此我将其(大约第 39 行)设置为列 CleanName 属性的值。
然后,这允许 DatabaseTable.cs 中的 GetColumnByPropertyName 方法(大约第 110 行)使用 PropertyName,而不是使用 Name。
我已将 Name 属性添加到 IColumn 接口,因为这似乎是一个疏忽,这意味着可以修改 Load 扩展方法(Database.cs 大约第 143 行)以访问传入对象的 Columns 属性(如果它是 IActiveRecord 的派生物)并使用它将“名称”映射到“属性名称”。
如果我有时间了解我们的 GitHub,我将提交更改。
干杯
加里
After running through the code base I think I've identified an easier solution (IMHO).
The IColumn interface has a 'PropertyName' property defined which I believe is designed to indicate the name of the property representing this column on the table class (akin to the 'ClassName' property on ITable). In the Structs.tt template this is not set so I have set it (circa line 39) to the value of the columns CleanName property.
This then allows the GetColumnByPropertyName method in DatabaseTable.cs (circa line 110) to use the PropertyName as opposed to using the Name.
I've added the Name property to the IColumn interface as it seemed to be an oversight, which then means that the Load extension method (Database.cs circa line 143) can be amended to access the Columns property of the passed in object (if it is a derivative of IActiveRecord) and use that to map the 'Name' to the 'PropertyName'.
If I can get the time to figure our GitHub I'll submit the changes.
Cheers
Gary