Reputation: 60691
CRM has a model generation tool, that can be used at development time in order to facilitate the usage of early binding. The data model is defined in this structure:
/// <summary>
/// Note that is attached to one or more objects, including other notes.
/// </summary>
[System.Runtime.Serialization.DataContractAttribute()]
[Microsoft.Xrm.Sdk.Client.EntityLogicalNameAttribute("annotation")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "5.0.9690.3339")]
public partial class Annotation : Microsoft.Xrm.Sdk.Entity, System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
{
/// <summary>
/// Default Constructor.
/// </summary>
public Annotation() :
base(EntityLogicalName)
{
}
public const string EntityLogicalName = "annotation";
public const int EntityTypeCode = 5;
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
private void OnPropertyChanged(string propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
private void OnPropertyChanging(string propertyName)
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, new System.ComponentModel.PropertyChangingEventArgs(propertyName));
}
}...
...
And the usage is very simple:
var note = new Annotation();
note.noteText = "this is my note";
..
Fields on the classes above all have some kind of defined bounds. For example, ints cannot be negative, strings need to be under 10 chars, etc
Is it possible to trick the model generator tool to include attributes on fields?
The intended result is to have a class that has bounds on every field:
public class Product
{
public int Id { get; set; }
[Required]
[StringLength(10)]
public string Name { get; set; }
[Required]
public string Description { get; set; }
[DisplayName("Price")]
[Required]
[RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]
public decimal UnitPrice { get; set; }
}
Upvotes: 0
Views: 58
Reputation: 18895
The CrmSvcUtil allows for you to extend the model and you could add your own attributes, via implementing one of their interfaces, I believe the ICodeGenerationService. You'll have to understand how to manipulate the CodeDom which is very verbose.
Upvotes: 3