ReadOnlyRoot.cst
Old forum URL: forums.lhotka.net/forums/t/1442.aspx
smark posted on Tuesday, October 10, 2006
Generating from ReadOnlyRoot.cst gives me the following exception:
------------------------------------------------------------------------------------------------
System.Exception: Unique Column(s) is required.
at CodeSmith.Csla.TemplateBase.ObjectInfo.Validate()
at CodeSmith.Csla.TemplateBase.ObjectInfo.LoadFromSchema(CodeTemplate template)
at CodeSmith.Csla.TemplateBase.ObjectInfo..ctor(CodeTemplate template)
at _CodeSmith.ReadOnlyRoot_cst.__RenderMethod1(TextWriter writer, Control control)
at CodeSmith.Engine.DelegateControl.Render(TextWriter writer)
at CodeSmith.Engine.Control.RenderChildren(TextWriter writer)
at CodeSmith.Engine.CodeTemplate.Render(TextWriter writer)
at CodeSmith.Engine.CodeTemplate.RenderToString()
at CodeSmith.Gui.CodeTemplateGenerator.f(Object A_0, EventArgs A_1)
------------------------------------------------------------------------------------------------
I selected a RootCommand and even supplied the name of the unique column, a Guid primary key column after the exception, but I keep getting the exception. Now, I do not get the exception if I select the RootTable option. However, I only want a couple of columns ( the primary key Guid column, and a string column) in this ReadOnlyRoot and selecting the RootTable option pulls out all the columns.
I am obviously missing something. Any suggestion would be greatly appreciated. Thanks.
rasupit replied on Tuesday, October 10, 2006
Can you post how your stored procedure look like? Is this for C# or VB?
Ricky
smark replied on Tuesday, October 10, 2006
This is for C#. And the sproc is just a simple select as in/for ProjectInfo in CSLA ProjectTracker.
Select [pkGuidColumn], [stringName]
From Table
Where Deleted = 0
Order By [Name]
Thanks.
rasupit replied on Tuesday, October 10, 2006
The sproc does not look like the kind you would use for a root object. For root object, all sproc parameter(s) will be the unique columns.
Try to use a stored procedure that would return a single record such as getProject in PTracker.
Ricky
smark replied on Tuesday, October 10, 2006
I think I am headed the wrong path. What I wanted was a ReadOnlyListBase derived collection such as the ProjectList in PTracker. The child object in ProjectList is ProjectInfo which is derived from ReadOnlyBase. I guess we currently do not have a template that would generate a class such as ProjectInfo -- basically a couple of properties: a Guid/Id value and a string value.
So I generated my ReadOnlyListBase class from ReadOnlyRootList.cst and thought I could generate a ProjectInfo-like class from ReadOnlyRoot.cst which is based on ReadOnlyBase. But that doesn't appear to be the case.
So what I am doing right now is hand-coding a ProjectInfo-like class that provides ReadOnlyBase objects to the generated ReadOnlyListBase class. And later may be I could write a template for a ProjectInfo-like class; that could be a good way to learn CodeSmith.
Thanks Ricky.
rasupit replied on Wednesday, October 11, 2006
Well, in this case you'll use ReadOnlyRootList & ReadOnlyChild template.
However, I found there is bug which would not allow you to generate ReadOnlyChild using the sproc above. The template would return the same error message and would not accept unique column entry.
I'll have this fixed for the next release. In the mean time, you can change line 1436 on TemplateBase.cs to:
if (resultSetIndex == 0 && !IsChild && CslaObjectType != ObjectType.NameValueList)
I think this will solve the problem.
Ricky
smark replied on Friday, October 13, 2006
Thanks Ricky
ChristianPena replied on Monday, October 23, 2006
Thanks for this. A co-worker pointed this out in our VB templates and I wasn't sure where to begin looking. He had a similar stored procedure.
Christian
Copyright (c) Marimer LLC