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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using System.ComponentModel ;
using System.ComponentModel.DataAnnotations ;
using System.ComponentModel.DataAnnotations.Schema ;
namespace Common.Core
{
/// <summary>
/// 数据库Id为numberic且为数据库自动生成的数据实体使用该基类, 用法同Entity
/// <para>该场景通常为SqlServer的自动增长类型和Oracle自带的Sequence</para>
/// </summary>
public class IntAutoGenEntity : BaseEntity
{
[Browsable(false)]
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get ; set ; }
public override bool KeyIsNull ( )
{
return Id = = 0 ;
}
public override void GenerateDefaultKeyVal ( )
{
//主键自动增长类型,可以不用该方法生成主键,设置该方法为空方法即可
//当DbContext执行SaveChanges()后, 如果添加成功, 可以直接获取对象的Id
}
}
}