New Posts New Posts RSS Feed: Metadata
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Metadata

 Post Reply Post Reply
Author
danjal View Drop Down
Groupie
Groupie


Joined: 20-Sep-2010
Posts: 43
Post Options Post Options   Quote danjal Quote  Post ReplyReply Direct Link To This Post Topic: Metadata
    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?


Edited by danjal - 30-Sep-2010 at 8:53am
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down