Print Page | Close Window

Metadata

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2206
Printed Date: 27-Apr-2025 at 11:30pm


Topic: Metadata
Posted By: danjal
Subject: Metadata
Date Posted: 30-Sep-2010 at 8:17am
Hi,
 
We are using Devforce 2010 with VS 2010.
We want to change the display attribute for the properties in our entity classes and later we will use the required attribute and regularexpression attribute.
We have tried this, but it has no affect, when we view the data in a DataForm:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using IdeaBlade.Core.ComponentModel.DataAnnotations;

namespace DomainModel{
[MetadataType(typeof(MetadataEntCustomer))]
public partial class EntCustomer
{
public static class MetadataEntCustomer
{
[ReadOnly(true)]
[Display(Name="Customer ID")]
public static int p_customerID;
}
}
}

I see that it is also possible to change this properties in the .edmx file.
What is the right way to change this properties?



Replies:
Posted By: DenisK
Date Posted: 01-Oct-2010 at 10:52am
Hi danjal;

The simplest way to change the DisplayName attribute is through the .edmx file.

To retrieve it, you can use the following code:

var displayName = GetDisplayNameAttribute(typeof(Customer), Customer.PropertyMetadata.Phone.Name);

public String GetDisplayNameAttribute(Type entityType, String propertyName) {
      var propertyInfo = entityType.GetProperty(propertyName);

      var attributes = (DisplayAttribute)propertyInfo.GetCustomAttributes(typeof(DisplayAttribute), false).First();

      return attributes.Name;
    }

Hope this helps.


Posted By: DenisK
Date Posted: 01-Oct-2010 at 12:48pm
Hi danjal;

I would like to add that there is also a much easier way to access the DisplayName attribute.

var displayName = Customer.PropertyMetadata.Phone.MemberMetadata.DisplayName;


The PropertyMetadata and the MemberMetadata class contain many of relatively easily accessible metadata about the properties of an entity.




Print Page | Close Window