开发者

StringTemplate can not render attribute of LINQ to SQL class

i use GUI tool of vs2008 to generate some LINQ to SQL class, my problem is Stri开发者_JAVA百科ngTemplate can not reach attributes of those model

$persons:{
<li>$it.name$</li>
}$

it printed:

<li></li>
<li></li>
<li></li>

name is public property of Person model. If i create a person class by myself, and the same attributes, StringTemplate can get it.


The designer produces a normal class with respect to the compiler, the code is simply autogenerated. I suspect that you have some other issue going on -- perhaps you haven't included the correct references/namespaces or you have a namespace conflict and it's picking the wrong class.


This is not the correct solution, but I am having the same trouble, and using $it._name$ works for me. This is accessing the private backing field though, so is not a good idea. Still, it means that StringTemplate can find that field, but not the name property to go with it. Odd.

Edit:

Got it. StringTemplate assumes that properties start with an uppercase letter. so if your property was called Name it would work. You could rename your properties or fix the offending bit of code in StringTemplate's source at ASTExpr.cs:RawGetObjectProperty around the call to GetPropertyValueByName (it uses methodSuffix, not propertyName).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜