2017-03-05 59 views
0

CRM有一個模型generation tool,可以在開發時使用,以便於使用早期綁定。數據模型在這個結構中定義:爲什麼crm動力學模型沒有屬性驗證?

/// <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)); 
      } 
     }... 
... 

而且用法很簡單:

var note = new Annotation(); 
note.noteText = "this is my note"; 
.. 

場以上的所有類都有某種定義界限。例如,整數不能是負數,字符串需要在10個字符以內,etc

是否有可能誘騙模型生成器工具在字段中包含屬性?

預期的結果是有對各個領域的邊界類:

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; } 
} 
+1

看看https://crmcodegenerator.codeplex.com/。我與這個項目沒有任何關係,並沒有使用它,但我一直很感興趣的是看到用'T4模板替換'CrmSvcUtil.exe'(對我來說,這是在.NET/Visual中執行代碼的正確方法工作室世界 – Nicknow

+0

@Nicknow請將其作爲答案 –

回答

4

的CrmSvcUtil允許你擴展模型,你可以添加自己的屬性,通過實施其接口之一,我相信ICodeGenerationService。您必須瞭解如何操作非常冗長的CodeDom。

相關問題