Esempio n. 1
0
        /// <summary>
        /// 批量刷新待存储的实体对象的主键,如果是主表的话要注意子表是否有关联。
        /// 特殊说明:不建议刷新主表的主键。
        /// 主键名称只支持名称为 ID;     if (entity.GetType().IsSubclassOf(typeof(MB.Orm.Common.BaseModel))) {
        /// </summary>
        /// <param name="dataInDocType">需要刷新主键的实体类型。</param>
        protected virtual void BatchSettingNewEntityID(int dataInDocType)
        {
            var entitys = from item in _ObjectDataList.Values
                          where (item.ObjectData as MB.Orm.Common.BaseModel) != null &&
                          ((MB.Orm.Common.BaseModel)item.ObjectData).EntityState == EntityState.New &&
                          (int)item.DataInDocType == dataInDocType
                          select item.ObjectData;
            int count = entitys.Count();

            if (count > 0)
            {
                int ids = this.GetCreateNewEntityIds(dataInDocType, count);
                MB.Util.Emit.DynamicPropertyAccessor ac = new Util.Emit.DynamicPropertyAccessor(entitys.First().GetType(), "ID");

                foreach (var entity in entitys)
                {
                    ac.Set(entity, ids++);
                }
            }
        }