Partial类的使用:
namespace Partial01
{
using System;
using System.Collections.Generic;
public partial class Book
{
public int ID { get; set; }
public string Name { get; set; }
public Nullable<decimal> Price { get; set; }
public string Author { get; set; }
}
}
添加一个新的类,将上边的代码复制,保持“命名空间”与 “类名”不变。
只修改类中的属性。在EntityFramework中,避免上边自动升级后,造成下边代码的更改。
namespace Partial01
{
using System;
using System.Collections.Generic;
public partial class Book
{
public string Report()
{
return $"# {this.ID} Name: {this.Name} Price: {this.Price}";
}
}
}
WPF,windows from,Ado.net core 都是应用partial类