A couple of suggestions

Aug 18, 2010 at 10:54 AM
Edited Aug 18, 2010 at 10:59 AM
I have spent a couple of days playing with the template and have a couple of sugestions.

For Editable Collections you use the BusinessListBase. Have you thought about changing that to BusinessBindingListBase? My first test was to add a child collection to a GridView and try to add items. I had to update the template in order to get defaults.

Second. You might want to add On<Property>Changed and On<Property>Changed partial subroutines. That way the developer can hook elegantly into changing properties before and after the setting. This is the same behavior EF has.

I changed the template to look like this

#region Properties
<#+
if(!entity.IsItemReadonly)
{
#>
public static PropertyInfo<byte[]> EntityKeyProperty = RegisterProperty<byte []>(c => c.EntityKey);
public byte[] EntityKey
{
get { return GetProperty<byte[]>(EntityKeyProperty); }
set { SetProperty<byte[]>(EntityKeyProperty, value); }
}
<#+
}
#>
<#+
foreach (Property property in entity.Properties)
{
///
/// Register Property
///
if (property.HasGetter || property.HasSetter)
{
#>

<#= property.PropInfoAccessibility #> static PropertyInfo<<#= property.DataTypeName #>> <#= property.Name #>Property = RegisterProperty<<#= property.DataTypeName #>>(c => c.<#= property.Name #><#= !string.IsNullOrEmpty(property.FriendlyName) ? string.Format(", \"{0}\"", property.FriendlyName) : string.Empty #>);
<#+
if (!string.IsNullOrEmpty(property.Description))
{
#>
/// <summary>
/// <#= property.Description #>
/// </summary>
<#+
}
#>
<#+
///
/// Property Definition
///
#>
<#= ctx.Code.SpaceAfter(property.PropAccessibility) #><#= property.DataTypeName #> <#= property.Name #>
{
<#+
if (property.HasGetter)
{
#>
<#= ctx.Code.SpaceAfter(property.GetterAccessibility) #>get { return GetProperty<<#= property.DataTypeName #>>(<#= property.Name #>Property); }
<#+
}

if (property.HasSetter)
{
#>
<#= ctx.Code.SpaceAfter(property.SetterAccessibility) #>set {
On<#= property.Name #>PropertyChanging(value);
SetProperty<<#= property.DataTypeName #>>(<#= property.Name #>Property, value);
On<#= property.Name #>PropertyChanged();
}
<#+
}
#>
}
partial void On<#= property.Name #>PropertyChanging(<#= property.DataTypeName #> value);
partial void On<#= property.Name #>PropertyChanged();

<#+
}
}
#>
#endregion // Properties
<#+
}
#>

<#+
/// <summary>
/// Generate Navigation Properties.
/// </summary>
/// <param name="entity"></param>
private void GenNavigationProperties(Entity entity)
{
#>

#region Navigation Properties
<#+
foreach (NavigationProperty property in entity.NavigationProperties)
{
///
/// Register Navigation Property
///
if (property.HasGetter || property.HasSetter)
{
#>

<#= property.PropInfoAccessibility #> static PropertyInfo<<#= property.DataTypeName #>> <#= property.Name #>Property = RegisterProperty<<#= property.DataTypeName #>>(c => c.<#= property.Name #>);
<#+
if (!string.IsNullOrEmpty(property.Description))
{
#>
/// <summary>
/// <#= property.Description #>
/// </summary>
<#+
}
#>
<#+
///
/// Navigation Property Definition
///
#>
<#= ctx.Code.SpaceAfter(property.PropAccessibility) #><#= property.DataTypeName #> <#= property.Name #>
{
<#+
if (property.HasGetter)
{
#>
<#= ctx.Code.SpaceAfter(property.GetterAccessibility) #>get { return GetProperty<<#= property.DataTypeName #>>(<#= property.Name #>Property); }
<#+
}

if (property.HasSetter)
{
#>
<#= ctx.Code.SpaceAfter(property.SetterAccessibility) #>set
{
On<#= property.Name #>PropertyChanging(value);
SetProperty<<#= property.DataTypeName #>>(<#= property.Name #>Property, value);
<#+
foreach (ReferentialConstraintProperties constraint in property.ReferentialConstraints)
{
#>
SetProperty<<#= constraint.DataTypeName #>>(<#= constraint.ToPropertyName #>Property, value.<#= constraint.FromPropertyName #>);
<#+
}
#>
On<#= property.Name #>PropertyChanged();
}
<#+
}
#>
}
partial void On<#= property.Name #>PropertyChanging(<#= property.DataTypeName #> value);
partial void On<#= property.Name #>PropertyChanged();
<#+
} // if (property.HasGetter || property.HasSetter)
} // foreach (NavigationProperty property in entity.NavigationProperties)
#>

#endregion // Navigation Properties



Finally a question about how you handle your Entity Framework Model.

How do you model ReadOnly "Info" Objects with editable 'main' Object. For example an OrderDetail would have a ProductInfo ReadOnly child and a Product EditableRoot. I cludged a solution adding Views to my database, importing them into the model and then changing the relationships for any references. It is of course less than ideal because you have to delete any FK relationships in the Model everytime you regenerate. Doable but really annoying. Do you have a better way?

Thanks. Very nice tool.