【发布时间】:2017-03-05 02:08:14
【问题描述】:
CRM 有一个模型generation tool,可以在开发时使用,以便于使用早期绑定。数据模型在这个结构中定义:
/// <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; }
}
【问题讨论】:
-
看看crmcodegenerator.codeplex.com。我与这个项目没有关系,也没有使用它,但我一直很想看到
CrmSvcUtil.exe被 T4 模板取代(对我来说,这是在 .NET/Visual Studio 世界中进行代码生成的正确方法. -
@Nicknow 请将其作为答案
标签: c# asp.net .net visual-studio dynamics-crm-2011