From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books
As soon as I run the template that generates business objects from the XML file. The error gets output to the window on the template.
Will
The error occurs at this point in the TemplateBase.cs file.
if (_uniqueProperties.Count == 0 && !IsCollection) throw new Exception("Unique Column(s) is required.");
AFAIK the _uniqueProperties property gets assigned when the XML for property contains an attribute of IsPrimaryKey="true"
As you can see, I have this attribute
<Property Name="ID" Type="int" IsPrimaryKey="true" IsIdentity="true" DbColumnName="ID" Description="" Default="" DataType="Int32" NativeType="Int32" SystemType="Int32">
The more I play with the templates the more it seems like the order of the attributes in a tag play a very large role in the generation, or possibly the addition of attributes the generator doesn't expect. Instead of just skipping them, the new attributes cause the generator not to function.
Just a guess. This is why I've requested an XSD for the XML the generator expects. If one is available.
Thanks,
Hey rasupit
Thanks for the heads up on the XSD. I am now generating valid XML to create code against. However, I have now also identified a true issue.
The XSD will allow the creation of empty <ValidationRules/> nodes. This however, causes the generator to throw that "Unique Column(s)" error. If I remove those blank nodes then I generate fine.
The XML at the end of this post validates fine against that XSD using XMLSpy2007.
So, now the dilema is should I write my XML Generator check if I need a validation before including the tag or should the template that generates the C# be altered to ignore the empty validatin tags? I'd prefer the latter approach since the former approach requires me to build a string for the validationRules then after the rules are processed check if my string is not equal to "<ValidatinRules></ValidationRules>" If not then emit the XML.
I think it would be more correct to have the code generator template simply ignore an empty ValidationRules block.
Thanks, Will
Here is my XML
<?xml version="1.0" encoding="UTF-8"?>
<
<ProjectName>MyApp.Library</ProjectName>
<GenerationMethod>SplitPartial</GenerationMethod>
<Objects>
<Object Access="public" Type="EditableRoot" Name="BuildingER" Namespace="MyCSLA">
<TransactionalType>TransactionScope</TransactionalType>
<PropertyAuthorization>Write</PropertyAuthorization>
<AuthorizationRules>false</AuthorizationRules>
<Properties>
<Property Access="private" Name="ID" Type="int" DbColumnName="ID" IsPrimaryKey="true" IsIdentity="true">
<ValidationRules/>
</Property>
<Property Access="private" Name="Name" Type="string" DbColumnName="Name">
<Property Access="private" Name="CompanyID" Type="int" DbColumnName="CompanyID">
</Properties>
<DbCommands DbName="PTracker">
<FetchCommand Type="StoredProcedure">gen_BuildingER_Fetch</FetchCommand>
<InsertCommand>gen_BuildingER_Insert</InsertCommand>
<UpdateCommand>gen_BuildingER_Update</UpdateCommand>
<DeleteCommand>gen_BuildingER_Delete</DeleteCommand>
</DbCommands>
</Object>
</Objects>
</CslaProject>
Ok, scratch that. Turns out that it wasn't the ValidationsTag but the simple fact of having to "Save" the XML file after I generate it. I'd generate and refresh it in XMLLSpy then the code generation would fail with the given error. However, if I click "Save" in XMLSpy then the CSLA code generates just fine.
So, now I'm generating code. Yay!