我刚加入一家新公司,我的经理也加入了,他想改变我们的计划。基本上做他做的事情。我不知道有什么区别,优点,缺点,限制和问题,如果有会any..here的样品什么是为模型类创建元数据类和部分类的用法#
namespace Models //this is the model part of from edmx
{
using System;
using System.Collections.Generic;
public partial class MyModelClass
{
public int ID { get; set; }
public Nullable<System.DateTime> PostDate { get; set; }
public string MyContent { get; set; }
}
}
这是元数据:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Models
{
public class MyModelMetaData
{
//he wants all data annotation here
public int ID { get; set; }
public Nullable<System.DateTime> PostDate { get; set; }
public string MyContent { get; set; }
}
}
这是部分:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace Models
{
[MetadataType(typeof(MyModelMetaData))]
public partial class MyModelClass or MyModelClassPartial
{
//He wants the programming algorithm to go here
}
}
请赐教。他希望为每个模型类别创建不同的元数据和部分类。
谢谢你..我需要一个答案,为什么..如果你认为他的方法是好的..我会这样做..但如果你认为这将导致未来的问题和更多的编码将涉及。 .i需要知道
为什么不问他他 – pm100
他没有解释..他只是想让我们这样做..coz这就是他如何学习它..他也是mvc的新手。 – CyberNinja
好好思考一下。如果MyClass是自动生成的,并为其添加数据注释属性。如果你改变模型会发生什么? 我认为他的建议在这种情况下是好的。 –