Skip to content

如何支持数据库实体定义雪花ID并自动赋值 #31

Answered by luoyunchong
fzwu asked this question in Q&A
Discussion options

You must be logged in to vote

或第二种方式

FreeSqlBuilder配置优先级,按顺序覆盖的逻辑,最后的那个优先级最高

UseMappingPriority(MappingPriorityType.FluentApi, MappingPriorityType.Attribute, MappingPriorityType.Aop)
  fsql.Aop.AuditValue += (s, e) =>
  {
      if (e.Column.CsType == typeof(long) && e.Property.Name == "Id" && e.Value?.ToString() == "0")
      {
          e.Value = YitIdHelper.NextId();
      }
  };
  fsql.Aop.ConfigEntityProperty += (s, e) =>
  {
      if ( e.Property.Name == "Id")
          e.ModifyResult.IsIdentity = false;
  };

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@fzwu
Comment options

@fzwu
Comment options

@luoyunchong
Comment options

@fzwu
Comment options

@luoyunchong
Comment options

Comment options

You must be logged in to vote
1 reply
@fzwu
Comment options

Answer selected by fzwu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants