Databases Reference
In-Depth Information
[ CustomProperty (Expression = “Supplier.Country”)]
public string Country { get { return this.Supplier.Country; } }
NOTE
Eliminating the UIHintAttribute and FilterUIHintAttribute from the entity model
not only reduces the amount of code you must write, but also changes the nature of
this code. Unlike the low-level hint annotations, the CustomPropertyAttribute does
not include hard-coded UI information.
Generating attributes is actually quite simple. If you have already created a class
that extends the built-in MetaColumn , you can do it by overriding the virtual
BuildAttributeCollection method, which, by default, simply returns the attributes
collection of the MetaColumn.Provider object. However, because the sample solution
already has an extended ColumnProvider , the easiest way to generate attributes is by
overriding its Attributes property. The following snippet shows an extract from the
UnleashedColumnProvider source code that demonstrates how to do this:
partial class UnleashedColumnProvider : ColumnProvider
{
public override AttributeCollection Attributes
{
get
{
var attributes = base.Attributes.Cast<Attribute>().ToList();
var customProperty = attributes.OfType<CustomPropertyAttribute>()
.FirstOrDefault();
if (customProperty != null &&
customProperty.Expression.Contains('.'))
{
string[] fields = customProperty.Expression.Split('.');
string foreignKeyField = fields[0];
string displayField = fields[1];
if (!attributes.OfType<UIHintAttribute>().Any())
{
attributes.Add(new UIHintAttribute(“Parent”, null,
“ForeignKeyField”, foreignKeyField,
“DisplayField”, displayField));
}
if (!attributes.OfType<FilterUIHintAttribute>().Any())
{
attributes.Add(new FilterUIHintAttribute(“Parent”, null,
“ForeignKeyField”, foreignKeyField,
“DisplayField”, displayField));
}
Search WWH ::




Custom Search