当前位置: 首页>>代码示例>>C#>>正文


C# DbEntityEntry.Cast方法代码示例

本文整理汇总了C#中DbEntityEntry.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# DbEntityEntry.Cast方法的具体用法?C# DbEntityEntry.Cast怎么用?C# DbEntityEntry.Cast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbEntityEntry的用法示例。


在下文中一共展示了DbEntityEntry.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnInsert

        public void OnInsert(DbEntityEntry entityEntry)
        {
            if (entityEntry.Entity is EntityWithCreatedDate)
                entityEntry.Cast<EntityWithCreatedDate>().Entity.Created = DateTime.Now;

            if (entityEntry.Entity is Entity)
                entityEntry.Cast<Entity>().Entity.Modified = DateTime.Now;
        }
开发者ID:Grinderofl,项目名称:YANBE,代码行数:8,代码来源:PreInsertEvent.cs

示例2: SetCreationAuditProperties

        private void SetCreationAuditProperties(DbEntityEntry entry)
        {
            if (entry.Entity is IHasCreationTime)
            {
                entry.Cast<IHasCreationTime>().Entity.CreationTime = DateTime.Now; //TODO: UtcNow?
            }

            if (entry.Entity is ICreationAudited)
            {
                entry.Cast<ICreationAudited>().Entity.CreatorUserId = AbpSession.UserId;
            }
        }
开发者ID:xueying,项目名称:aspnetboilerplate,代码行数:12,代码来源:AbpDbContext.cs

示例3: HandleSoftDelete

 private static void HandleSoftDelete(DbEntityEntry entry)
 {
     if (entry.Entity is ISoftDelete)
     {
         entry.State = EntityState.Unchanged;
         entry.Cast<ISoftDelete>().Entity.IsDeleted = true;
     }
 }
开发者ID:hersilio,项目名称:aspnetboilerplate,代码行数:8,代码来源:AbpDbContext.cs

示例4: SetModificationAuditProperties

 private void SetModificationAuditProperties(DbEntityEntry entry)
 {
     if (entry.Entity is IModificationAudited)
     {
         var auditedEntry = entry.Cast<IModificationAudited>();
         auditedEntry.Entity.LastModificationTime = DateTime.Now; //TODO: UtcNow?
         auditedEntry.Entity.LastModifierUserId = AbpSession.UserId;
     }
 }
开发者ID:xueying,项目名称:aspnetboilerplate,代码行数:9,代码来源:AbpDbContext.cs

示例5: SetModificationAuditProperties

        /// <summary>
        /// The set modification audit properties.
        /// </summary>
        /// <param name="entry">
        /// The entry.
        /// </param>
        protected virtual void SetModificationAuditProperties(DbEntityEntry entry)
        {
            if (!(entry.Entity is IModificationAudited))
            {
                return;
            }

            entry.Cast<IModificationAudited>().Entity.LastModificationTime = DateTime.Now;
            if (this.workContext != null && !string.IsNullOrEmpty(this.workContext.CurrentCustomerId))
            {
                entry.Cast<IModificationAudited>().Entity.LastModifierUserId = Guid.Parse(this.workContext.CurrentCustomerId);
            }
        }
开发者ID:ZhaoRd,项目名称:Ren_Framework,代码行数:19,代码来源:SkymateDataRepositoryContext.cs

示例6: SetCreationAuditProperties

        protected virtual void SetCreationAuditProperties(DbEntityEntry entry)
        {
            if (entry.Entity is IHasCreationTime)
            {
                entry.Cast<IHasCreationTime>().Entity.CreationTime = Clock.Now;
            }

            if (entry.Entity is ICreationAudited)
            {
                entry.Cast<ICreationAudited>().Entity.CreatorUserId = AbpSession.UserId;
            }
        }
开发者ID:Why-Not-Sky,项目名称:aspnetboilerplate,代码行数:12,代码来源:AbpDbContext.cs

示例7: CheckMayHaveTenant

        protected virtual void CheckMayHaveTenant(DbEntityEntry entry)
        {
            if (!this.IsFilterEnabled(AbpDataFilters.MayHaveTenant))
            {
                return;
            }

            var currentTenantId = (int?)this.GetFilterParameterValue(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId);

            var entity = entry.Cast<IMayHaveTenant>().Entity;

            if (entity.TenantId != currentTenantId && entity.TenantId != AbpSession.TenantId)
            {
                throw new DbEntityValidationException("Can not set TenantId to a different value than the current filter parameter value or IAbpSession.TenantId while MayHaveTenant filter is enabled!");
            }
        }
开发者ID:Why-Not-Sky,项目名称:aspnetboilerplate,代码行数:16,代码来源:AbpDbContext.cs

示例8: CheckAndSetMustHaveTenant

        protected virtual void CheckAndSetMustHaveTenant(DbEntityEntry entry)
        {
            var entity = entry.Cast<IMustHaveTenant>().Entity;

            if (!this.IsFilterEnabled(AbpDataFilters.MustHaveTenant))
            {
                if (AbpSession.TenantId != null && entity.TenantId == 0)
                {
                    entity.TenantId = AbpSession.GetTenantId();
                }

                return;
            }

            var currentTenantId = (int)this.GetFilterParameterValue(AbpDataFilters.MustHaveTenant, AbpDataFilters.Parameters.TenantId);

            if (currentTenantId == 0)
            {
                throw new DbEntityValidationException("Can not save a IMustHaveTenant entity while MustHaveTenant filter is enabled and current filter parameter value is not set (Probably, no tenant user logged in)!");
            }

            if (entity.TenantId == 0)
            {
                entity.TenantId = currentTenantId;
            }
            else if (entity.TenantId != currentTenantId && entity.TenantId != AbpSession.TenantId)
            {
                throw new DbEntityValidationException("Can not set IMustHaveTenant.TenantId to a different value than the current filter parameter value or IAbpSession.TenantId while MustHaveTenant filter is enabled!");
            }
        }
开发者ID:Why-Not-Sky,项目名称:aspnetboilerplate,代码行数:30,代码来源:AbpDbContext.cs

示例9: CheckMayHaveTenant

        protected virtual void CheckMayHaveTenant(DbEntityEntry entry)
        {
            if (!this.IsFilterEnabled(OwDataFilters.MayHaveTenant))
            {
                return;
            }

            var currentTenantId = (int?)this.GetFilterParameterValue(OwDataFilters.MayHaveTenant, OwDataFilters.Parameters.TenantId);

            var entity = entry.Cast<IMayHaveTenant>().Entity;

            if (entity.TenantId != currentTenantId && entity.TenantId != OwSession.TenantId)
            {
                throw new DbEntityValidationException("Can not set TenantId to a different value than the current filter parameter value or IOwSession.TenantId while MayHaveTenant filter is enabled!");
                //不能TenantId设置为不同的值比当前的过滤参数值或IOwSession。TenantId虽然MayHaveTenant启用过滤器!
            }
        }
开发者ID:zhongkai1010,项目名称:OneWork,代码行数:17,代码来源:OwDbContext.cs

示例10: SetModificationAuditProperties

        protected virtual void SetModificationAuditProperties(DbEntityEntry entry, long? userId)
        {
            if (entry.Entity is IHasModificationTime)
            {
                entry.Cast<IHasModificationTime>().Entity.LastModificationTime = Clock.Now;
            }

            if (entry.Entity is IModificationAudited)
            {
                var entity = entry.Cast<IModificationAudited>().Entity;

                if (userId == null)
                {
                    entity.LastModifierUserId = null;
                    return;
                }

                //Special check for multi-tenant entities
                if (entity is IMayHaveTenant || entity is IMustHaveTenant)
                {
                    //Sets LastModifierUserId only if current user is in same tenant/host with the given entity
                    if ((entity is IMayHaveTenant && entity.As<IMayHaveTenant>().TenantId == AbpSession.TenantId) ||
                        (entity is IMustHaveTenant && entity.As<IMustHaveTenant>().TenantId == AbpSession.TenantId))
                    {
                        entity.LastModifierUserId = userId;
                    }
                    else
                    {
                        entity.LastModifierUserId = null;
                    }
                }
                else
                {
                    entity.LastModifierUserId = userId;
                }
            }
        }
开发者ID:Zbun,项目名称:Gld.Activity.Project,代码行数:37,代码来源:AbpDbContext.cs

示例11: HandleSoftDelete

        protected virtual void HandleSoftDelete(DbEntityEntry entry)
        {
            if (!(entry.Entity is ISoftDelete))
            {
                return;
            }

            var softDeleteEntry = entry.Cast<ISoftDelete>();

            softDeleteEntry.State = EntityState.Unchanged;
            softDeleteEntry.Entity.IsDeleted = true;

            if (entry.Entity is IDeletionAudited<Guid>)
            {
                SetDeletionAuditProperties(entry.Cast<IDeletionAudited<Guid>>().Entity);
            }
        }
开发者ID:mlkj,项目名称:2016YL.MaterialSystem,代码行数:17,代码来源:AbpDbContext.cs

示例12: SetModificationAuditProperties

        protected virtual void SetModificationAuditProperties(DbEntityEntry entry)
        {
            if (entry.Entity is IModificationAudited)
            {
                var auditedEntry = entry.Cast<IModificationAudited>();

                auditedEntry.Entity.UpdateTime = ClockManager.Now;
                auditedEntry.Entity.UpdateUserId = QdfSession.UserId;
            }
        }
开发者ID:lizhi5753186,项目名称:QDF,代码行数:10,代码来源:QdfDbContext.cs

示例13: OnUpdate

 public void OnUpdate(DbEntityEntry entityEntry)
 {
     if (entityEntry.Entity is Entity)
         entityEntry.Cast<Entity>().Entity.Modified = DateTime.Now;
 }
开发者ID:Grinderofl,项目名称:YANBE,代码行数:5,代码来源:PreUpdateEvent.cs

示例14: SetModificationAuditProperties

        /// <summary>
        /// The set modification audit properties.
        /// </summary>
        /// <param name="entry">
        /// The entry.
        /// </param>
        protected virtual void SetModificationAuditProperties(DbEntityEntry entry)
        {
            if (entry.Entity is IModificationAudited)
            {
                var auditedEntry = entry.Cast<IModificationAudited>();

                var userid = Guid.Parse(this.WorkContext.CurrentCustomerId);
                auditedEntry.Entity.LastModificationTime = DateTime.Now;
                auditedEntry.Entity.LastModifierUserId = userid;
            }
        }
开发者ID:ZhaoRd,项目名称:Ren_Framework,代码行数:17,代码来源:SkymateBaseDbContext.cs

示例15: SetCreationAuditProperties

        /// <summary>
        /// The set creation audit properties.
        /// </summary>
        /// <param name="entry">
        /// The entry.
        /// </param>
        protected virtual void SetCreationAuditProperties(DbEntityEntry entry)
        {
            if (entry.Entity is IHasCreationTime)
            {
                entry.Cast<IHasCreationTime>().Entity.CreationTime = DateTime.Now; // Clock.Now;
            }

            if (entry.Entity is ICreationAudited)
            {
                var userid = Guid.Parse(this.WorkContext.CurrentCustomerId);
                entry.Cast<ICreationAudited>().Entity.CreatorUserId = userid;
            }
        }
开发者ID:ZhaoRd,项目名称:Ren_Framework,代码行数:19,代码来源:SkymateBaseDbContext.cs


注:本文中的DbEntityEntry.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。