You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1007 B
C#

3 years ago
using Common.Snowflake;
using System.ComponentModel;
3 years ago
3 years ago
namespace Common.Core
3 years ago
{
/// <summary>
/// 数据库Id为numberic类型的数据实体使用该基类用法同Entity
/// 数据库Id字段为numberic(16,0)或以上长度的整型采用雪花算法生成Id。
/// </summary>
public class LongEntity : BaseEntity
{
[Browsable(false)]
public decimal Id { get; set; }
public override bool KeyIsNull()
{
return Id == 0;
}
static LongEntity()
{
//设置参数,程序初始化时执行一次
var options = new IdGeneratorOptions()
{
Method = 1,
WorkerId = 1
};
YitIdHelper.SetIdGenerator(options);
}
/// <summary>
/// 采用雪花算法计算Id
/// </summary>
public override void GenerateDefaultKeyVal()
{
Id = YitIdHelper.NextId();
}
}
}