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


C# DbContext.Entry方法代码示例

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


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

示例1: UpdateContextItem

        public static object UpdateContextItem(DbContext context,Object obj)
        {
            //将foreign key制空
            obj.GetType().GetProperties().ToList().ForEach(delegate (PropertyInfo pi)
            {
                var att = pi.GetCustomAttribute(typeof(ForeignKeyAttribute));
                if (att != null)
                {
                    pi.SetValue(obj, null);
                }

            });

            //修改操作为修改
            context.Entry(obj).State = EntityState.Modified;

            //重新加载foreign key的对象。
            obj.GetType().GetProperties().ToList().ForEach(delegate (PropertyInfo pi)
            {
                var att = pi.GetCustomAttribute(typeof(ForeignKeyAttribute));
                if (att != null)
                {
                    context.Entry(obj).Reference(pi.Name).Load();
                }
            });
            return obj;
        }
开发者ID:amwtke,项目名称:bkwecaht,代码行数:27,代码来源:RepositoryHelper.cs

示例2: Update

 public void Update(DbContext DbContext,ManufacturePlanItem entity)
 {
     EntityState state = DbContext.Entry(entity).State;
        if (state == EntityState.Detached)
        {
       DbContext.Entry(entity).State = EntityState.Modified;
     }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:8,代码来源:ManufacturePlanItemRpt.cs

示例3: Update

 public void Update(DbContext DbContext,ProductWareStock entity)
 {
     EntityState state = DbContext.Entry(entity).State;
        if (state == EntityState.Detached)
        {
       DbContext.Entry(entity).State = EntityState.Modified;
     }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:8,代码来源:ProductWareStockRpt.cs

示例4: Update

 public void Update(DbContext DbContext,ArticleAnnex entity)
 {
     EntityState state = DbContext.Entry(entity).State;
        if (state == EntityState.Detached)
        {
       DbContext.Entry(entity).State = EntityState.Modified;
     }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:8,代码来源:ArticleAnnexRpt.cs

示例5: Update

 public void Update(DbContext DbContext,CompanyClientType entity)
 {
     EntityState state = DbContext.Entry(entity).State;
        if (state == EntityState.Detached)
        {
       DbContext.Entry(entity).State = EntityState.Modified;
     }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:8,代码来源:CompanyClientTypeRpt.cs

示例6: Update

 public void Update(DbContext DbContext,Facility entity)
 {
     EntityState state = DbContext.Entry(entity).State;
        if (state == EntityState.Detached)
        {
       DbContext.Entry(entity).State = EntityState.Modified;
     }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:8,代码来源:FacilityRpt.cs

示例7: Update

 public void Update(DbContext DbContext,MaterialPurchasePlan entity)
 {
     EntityState state = DbContext.Entry(entity).State;
        if (state == EntityState.Detached)
        {
       DbContext.Entry(entity).State = EntityState.Modified;
     }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:8,代码来源:MaterialPurchasePlanRpt.cs

示例8: CheckValue

        public void CheckValue(DbContext ctx, object actual)
        {
            var propertyType = Accessor.MemberType;

            var objectContext = ((IObjectContextAdapter)ctx).ObjectContext;
            var entitySet = objectContext.GetEntitySet(propertyType);
            var keyMembers = entitySet.ElementType.KeyMembers;

            ctx.Entry(actual).Reference(Accessor.Name).Load();

            var actualEntity = Accessor.GetValue(actual);
            if (actualEntity == null)
            {
                throw new AssertionException(ExpectedEntity.Dump(), "NULL");
            }
            foreach (var keyMember in keyMembers)
            {
                var accessor = new PropertyAccessor(propertyType.GetProperty(keyMember.Name));

                var actualKeyValue = accessor.GetValue(actualEntity);
                var expectedKeyValue = accessor.GetValue(ExpectedEntity);

                if (!expectedKeyValue.Equals(actualKeyValue))
                {
                    throw new AssertionException(ExpectedEntity.Dump(), actualEntity.Dump());
                }
            }
        }
开发者ID:kmcginnes,项目名称:EFSpecs,代码行数:28,代码来源:Reference.cs

示例9: AppendDescriptionUsingContext

        private static void AppendDescriptionUsingContext(DbContext context, StringBuilder builder, EntityType type, ActionType aType, object entity)
        {
            string additionalInfo = string.Empty;
            string identity = string.Empty;
            var enrty = context.Entry(entity);

            var prop =
                enrty.Entity.GetType()
                    .GetProperties()
                    .FirstOrDefault(c => c.GetCustomAttributes(typeof(KeyAttribute), true).FirstOrDefault() != null);
            var name = enrty.Entity.GetType().GetProperties().FirstOrDefault(c => c.Name.Contains("Name"));

            identity = CreateIdentityString(entity, prop, identity, name);

            if (aType == ActionType.Updating)
            {
                additionalInfo = string.Format("Были изменены следующие поля: {0}",
                    string.Join(",", enrty.CurrentValues.PropertyNames));
            }

            if (aType != ActionType.Import || aType != ActionType.Export)
            {
                builder.Append(string.Format("Сущность \"{0}\" {1} была {2}.{3}", type.GetEntityTypeName(), identity,
                    aType.GetActionTypeName(), additionalInfo));
            }
        }
开发者ID:Shkorodenok,项目名称:Articles,代码行数:26,代码来源:TransactionHelper.cs

示例10: Insert

 public void Insert(DbContext DbContext, IEnumerable<Facility> entities)
 {
     try
        {
       DbContext.Configuration.AutoDetectChangesEnabled = false;
       foreach (Facility  entity in entities)
       {
     DbContext.Entry(entity).State = EntityState.Added;
       }
        }
        finally
        {
      DbContext.Configuration.AutoDetectChangesEnabled = true;
        }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:15,代码来源:FacilityRpt.cs

示例11: Delete

 public void Delete(DbContext DbContext, IEnumerable<CompanyClientType> entities)
 {
     try
        {
       DbContext.Configuration.AutoDetectChangesEnabled = false;
       foreach (CompanyClientType  entity in entities)
       {
      DbContext.Entry(entity).State = EntityState.Deleted;
       }
        }
        finally
        {
      DbContext.Configuration.AutoDetectChangesEnabled = true;
        }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:15,代码来源:CompanyClientTypeRpt.cs

示例12: Delete

 public void Delete(DbContext DbContext, IEnumerable<MaterialPurchasePlan> entities)
 {
     try
        {
       DbContext.Configuration.AutoDetectChangesEnabled = false;
       foreach (MaterialPurchasePlan  entity in entities)
       {
      DbContext.Entry(entity).State = EntityState.Deleted;
       }
        }
        finally
        {
      DbContext.Configuration.AutoDetectChangesEnabled = true;
        }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:15,代码来源:MaterialPurchasePlanRpt.cs

示例13: Delete

 public void Delete(DbContext DbContext, IEnumerable<ProductWareStock> entities)
 {
     try
        {
       DbContext.Configuration.AutoDetectChangesEnabled = false;
       foreach (ProductWareStock  entity in entities)
       {
      DbContext.Entry(entity).State = EntityState.Deleted;
       }
        }
        finally
        {
      DbContext.Configuration.AutoDetectChangesEnabled = true;
        }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:15,代码来源:ProductWareStockRpt.cs

示例14: Delete

 public void Delete(DbContext DbContext, IEnumerable<ArticleAnnex> entities)
 {
     try
        {
       DbContext.Configuration.AutoDetectChangesEnabled = false;
       foreach (ArticleAnnex  entity in entities)
       {
      DbContext.Entry(entity).State = EntityState.Deleted;
       }
        }
        finally
        {
      DbContext.Configuration.AutoDetectChangesEnabled = true;
        }
 }
开发者ID:liurongjin,项目名称:frame,代码行数:15,代码来源:ArticleAnnexRpt.cs

示例15: WritePropertyValidationResults

 public static void WritePropertyValidationResults(DbContext context, object model, params string[] propertyNames)
 {
     var entity = context.Entry(model);
     Console.WriteLine("Type: {0}", model.GetType().Name);
     foreach (string propertyName in propertyNames)
     {
         Console.WriteLine("\nProperty: {0}", propertyName);
         Console.WriteLine("Value: {0}", entity.Property(propertyName).CurrentValue);
         var results = entity.Property(propertyName).GetValidationErrors();
         Console.WriteLine("Passed Validation: {0}",!results.Any());
         foreach (DbValidationError dbValidationError in results)
         {
             Console.WriteLine("  - {0}", dbValidationError.ErrorMessage);
         }
     }
 }
开发者ID:JeremySBrown,项目名称:DbContextPresentation,代码行数:16,代码来源:TestHelpers.cs


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