Print Page | Close Window

DB First Metadata for custom property

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=3849
Printed Date: 05-Feb-2026 at 2:45pm


Topic: DB First Metadata for custom property
Posted By: pglaspey
Subject: DB First Metadata for custom property
Date Posted: 10-Dec-2012 at 10:54am
How do I get metadata generated for a custom property that only exists in the partial class file.

If I attribute it directly or add it to the helper class it does not work.

Is this possible?



Replies:
Posted By: kimj
Date Posted: 10-Dec-2012 at 3:53pm
You can add a DataEntityProperty for these "non-native" properties.
 
It looks like we don't have this documented, but you can "extend" the PropertyMetadata partial class for the entity to add the static DataEntityProperty field.  Something like this:
 
public partial class Customer {
  public string ACustomProp { get; set; }
 
  public partial class PropertyMetadata {

    public static readonly DataEntityProperty<Customer, string> ACustomProp  =
       new DataEntityProperty<Customer, string>(propertyName: "ACustomProp",
                                      isNullable: false,
                                      isPartOfKey: false,
                                      concurrencyStrategy: ConcurrencyStrategy.None,
                                      isAutoIncrementing: false,
                                      relatedNavigationPropertyName: null,
                                      isNativeProperty: false);
  }
}
 
DevForce will discover the property definitions when the model is accessed.  You can then obtain property metadata from the EntityMetdataStore.
 



Print Page | Close Window