2021-03-13 16:21:56 +08:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Repository.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数据库Id为numberic类型的数据实体使用该基类,用法同Entity
|
|
|
|
|
/// 数据库Id字段为numberic(16,0)或以上长度的整型,采用雪花算法生成Id。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class LongEntity :BaseEntity
|
|
|
|
|
{
|
|
|
|
|
[Browsable(false)]
|
2021-06-18 16:53:28 +08:00
|
|
|
|
public decimal Id { get; set; }
|
2021-03-13 16:21:56 +08:00
|
|
|
|
public override bool KeyIsNull()
|
|
|
|
|
{
|
|
|
|
|
return Id == 0;
|
|
|
|
|
}
|
2021-03-29 23:35:02 +08:00
|
|
|
|
|
|
|
|
|
static LongEntity()
|
|
|
|
|
{
|
|
|
|
|
//设置参数,程序初始化时执行一次
|
|
|
|
|
var options = new IdGeneratorOptions()
|
|
|
|
|
{
|
|
|
|
|
Method = 1,
|
|
|
|
|
WorkerId = 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
YitIdHelper.SetIdGenerator(options);
|
|
|
|
|
}
|
2021-03-13 16:21:56 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 采用雪花算法计算Id
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override void GenerateDefaultKeyVal()
|
|
|
|
|
{
|
2021-03-29 23:35:02 +08:00
|
|
|
|
Id = YitIdHelper.NextId();
|
2021-03-13 16:21:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|