• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Objects.ObjectStateEntry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Data.Objects.ObjectStateEntry的典型用法代码示例。如果您正苦于以下问题:C# ObjectStateEntry类的具体用法?C# ObjectStateEntry怎么用?C# ObjectStateEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ObjectStateEntry类属于System.Data.Objects命名空间,在下文中一共展示了ObjectStateEntry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: IsTargetEntity

        public virtual bool IsTargetEntity(ObjectStateEntry item)
        {

            return item.State != EntityState.Detached &&
                   TargetType.IsInstanceOfType(item.Entity);

        }
开发者ID:Eugene-Murray,项目名称:Contract_Validus,代码行数:7,代码来源:TypeInterceptor.cs


示例2: GetIdentifierValue

 /// <summary>
 /// Gets the identifier value for the entity in the ObjectStateEntry.
 /// </summary>
 /// <param name="objectStateEntry">The ObjectStateEntry.</param>
 /// <returns>The identifier value.</returns>
 /// <remarks>
 /// When auditing Adds, this needs to be called AFTER SaveChanges, or else it will return null.
 /// </remarks>
 public static string GetIdentifierValue(ObjectStateEntry objectStateEntry)
 {
     if (objectStateEntry == null)
     {
         throw new ArgumentNullException("objectStateEntry");
     }
     string id = null;
     var entityKey = objectStateEntry.EntityKey;
     if (entityKey != null)
     {
         var keyValues = entityKey.EntityKeyValues;
         if (keyValues != null)
         {
             if (keyValues.Length == 1)
             {
                 id = keyValues[0].Value.ToString();
             }
             else if (keyValues.Length > 1)
             {
                 id = string.Join(_composikeKeySeparator, keyValues.OrderBy(k => k.Key).Select(k => k.Value.ToString()).ToArray());
             }
         }
     }
     return id;
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:33,代码来源:IdentifierUtility.cs


示例3: TrackOriginalValue

 /// <summary>
 /// Tracks the original value.
 /// </summary>
 /// <param name="objectStateEntry">The object state entry.</param>
 private void TrackOriginalValue(ObjectStateEntry objectStateEntry)
 {
     object propertyValue = objectStateEntry.OriginalValues[PropertyName];
     if (propertyValue != null)
     {
         OriginalValue = propertyValue.ToString();
     }
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:12,代码来源:TrackingAuditEntityProperty.cs


示例4: TrackNewValue

 /// <summary>
 /// Tracks the new value.
 /// </summary>
 /// <param name="objectStateEntry">The object state entry.</param>
 private void TrackNewValue(ObjectStateEntry objectStateEntry)
 {
     object propertyValue = objectStateEntry.CurrentValues[PropertyName];
     if (propertyValue != null)
     {
         NewValue = propertyValue.ToString();
     }
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:12,代码来源:TrackingAuditEntityProperty.cs


示例5: GetUpdatedEntityValues

 private static IEnumerable<Tuple<string, object, object>> GetUpdatedEntityValues(ObjectStateEntry entry)
 {
     foreach (string propname in entry.GetModifiedProperties())
     {
         object newval = entry.CurrentValues[propname];
         object oldval = entry.OriginalValues[propname];
         yield return Tuple.Create(propname, newval, oldval);
     }
 }
开发者ID:koder05,项目名称:fogel-ba,代码行数:9,代码来源:EFExtension.cs


示例6: TrackDelete

 /// <summary>
 /// Tracks the delete.
 /// </summary>
 /// <param name="objectStateEntry">The object state entry.</param>
 public void TrackDelete(ObjectStateEntry objectStateEntry)
 {
     if (objectStateEntry == null)
     {
         throw new ArgumentNullException("objectStateEntry");
     }
     AuditEntities.Add(new EntityDeletedAudit(objectStateEntry));
     RemoveReads();
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:13,代码来源:TrackingAuditEvent.cs


示例7: TrackingAuditEntity

 public TrackingAuditEntity(ObjectStateEntry objectStateEntry, AuditEntityAction action)
 {
     if (objectStateEntry == null)
     {
         throw new ArgumentNullException("objectStateEntry");
     }
     EntityType = EntityTypeResolver.ResolveActualEntityType(objectStateEntry.Entity).Name;
     EntityIdentifier = IdentifierUtility.GetIdentifierValue(objectStateEntry);
     AuditEntityAction = action;
     AuditEntityProperties = new Collection<AuditEntityProperty>();
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:11,代码来源:TrackingAuditEntity.cs


示例8: GetAddedEntityValues

 private static IEnumerable<Tuple<string, object, object>> GetAddedEntityValues(ObjectStateEntry entry)
 {
     foreach (var propinfo in entry.CurrentValues.DataRecordInfo.FieldMetadata)
     {
         object newval = entry.CurrentValues[propinfo.FieldType.Name];
         if (newval.GetType() == typeof(EntityKey))
         {
             newval = ((EntityKey)newval).EntityKeyValues.Select(k => k.Value).FirstOrDefault();    
         }
         yield return Tuple.Create(propinfo.FieldType.Name, newval, (object)null);
     }
 }
开发者ID:koder05,项目名称:fogel-ba,代码行数:12,代码来源:EFExtension.cs


示例9: TrackProperties

 /// <summary>
 /// Tracks the properties.
 /// </summary>
 /// <param name="objectStateEntry">The object state entry.</param>
 protected void TrackProperties(ObjectStateEntry objectStateEntry)
 {
     var currentValues = objectStateEntry.CurrentValues;
     for (int ordinal = 0; ordinal < currentValues.FieldCount; ordinal++)
     {
         var propertyName = currentValues.GetName(ordinal);
         if (!IsStoreGenerated(propertyName, objectStateEntry))
         {
             AuditEntityProperties.Add(new TrackingAuditEntityProperty(propertyName, objectStateEntry));
         }
     }
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:16,代码来源:EntityAddedAudit.cs


示例10: GetAction

 private static AuditAction GetAction(ObjectStateEntry entity)
 {
     switch (entity.State)
     {
         case EntityState.Added:
             return AuditAction.Added;
         case EntityState.Deleted:
             return AuditAction.Deleted;
         default:
             return AuditAction.Modified;
     }
 }
开发者ID:dioptre,项目名称:nkd,代码行数:12,代码来源:AuditEntryState.cs


示例11: TrackProperties

 /// <summary>
 /// Tracks the properties.
 /// </summary>
 /// <param name="objectStateEntry">The object state entry.</param>
 protected void TrackProperties(ObjectStateEntry objectStateEntry)
 {
     foreach (string propertyName in objectStateEntry.GetModifiedProperties())
     {
         if (!IsStoreGenerated(propertyName, objectStateEntry))
         {
             var auditProperty = new TrackingAuditEntityProperty(propertyName, objectStateEntry);
             if (auditProperty.HasChanges)
             {
                 AuditEntityProperties.Add(auditProperty);
             }
         }
     }
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:18,代码来源:EntityUpdatedAudit.cs


示例12: ObjectStateEntryDbDataRecord

 internal ObjectStateEntryDbDataRecord(RelationshipEntry cacheEntry)
 {
     EntityUtil.CheckArgumentNull(cacheEntry, "cacheEntry");
     Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryDbDataRecord for a key entry");
     switch (cacheEntry.State)
     {
         case EntityState.Unchanged:
         case EntityState.Modified:
         case EntityState.Deleted:
             _cacheEntry = cacheEntry;
             break;
         default:
             Debug.Assert(false, "A DbDataRecord cannot be created for an entity object that is in an added or detached state.");
             break;
     }
 }
开发者ID:uQr,项目名称:referencesource,代码行数:16,代码来源:ObjectStateEntryDbDataRecord.cs


示例13: TrackingAuditEntityProperty

 /// <summary>
 /// Initializes a new instance of the <see cref="TrackingAuditEntityProperty"/> class.
 /// </summary>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="objectStateEntry">The object state entry.</param>
 public TrackingAuditEntityProperty(string propertyName, ObjectStateEntry objectStateEntry)
 {
     if (objectStateEntry == null)
     {
         throw new ArgumentNullException("objectStateEntry");
     }
     if (string.IsNullOrEmpty(propertyName))
     {
         throw new ArgumentNullException("propertyName");
     }
     PropertyName = propertyName;
     TrackNewValue(objectStateEntry);
     if (objectStateEntry.State == EntityState.Modified)
     {
         TrackOriginalValue(objectStateEntry);
     }
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:22,代码来源:TrackingAuditEntityProperty.cs


示例14: ValidateBelongsTo

		static void ValidateBelongsTo(this AssociationEndMember end, ObjectStateEntry entry)
		{
			if (!entry.IsRelationship)
			{
				throw new ArgumentException("is not a relationship entry", "entry");
			}

			var fieldMetadata =
					entry.UsableValues().DataRecordInfo.FieldMetadata;
			if (fieldMetadata[0].FieldType as AssociationEndMember != end &&
				fieldMetadata[1].FieldType as AssociationEndMember != end)
			{
				throw new InvalidOperationException(string.Format(
						"association end {0} does not participate in the " +
						"relationship {1}", end, entry));
			}
		}
开发者ID:ptrefren,项目名称:EntityFramework.Extended,代码行数:17,代码来源:Extensions.cs


示例15: ObjectStateEntryDbDataRecord

 internal ObjectStateEntryDbDataRecord(EntityEntry cacheEntry, StateManagerTypeMetadata metadata, object userObject)
 {
     //Contract.Requires(cacheEntry != null);
     //Contract.Requires(userObject != null);
     //Contract.Requires(metadata != null);
     Debug.Assert(!cacheEntry.IsKeyEntry, "Cannot create an ObjectStateEntryDbDataRecord for a key entry");
     switch (cacheEntry.State)
     {
         case EntityState.Unchanged:
         case EntityState.Modified:
         case EntityState.Deleted:
             _cacheEntry = cacheEntry;
             _userObject = userObject;
             _metadata = metadata;
             break;
         default:
             Debug.Assert(false, "A DbDataRecord cannot be created for an entity object that is in an added or detached state.");
             break;
     }
 }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:20,代码来源:ObjectStateEntryDbDataRecord.cs


示例16: IsStoreGenerated

 /// <summary>
 /// This determines if the value of the property is generated by the database (i.e. "Version"),
 /// in which case we don't want to store it as modified by the user.
 /// </summary>
 /// <param name="propertyName"></param>
 /// <param name="objectStateEntry"></param>
 /// <returns></returns>
 /// <remarks>
 /// This could potentially be a performance bottleneck.  If we need to speed things up,
 /// we can cache this information by type and propertyname in a static dictionary.
 /// </remarks>
 protected static bool IsStoreGenerated(string propertyName, ObjectStateEntry objectStateEntry)
 {
     bool returnValue = false;
     var metadataWorkspace = objectStateEntry.ObjectStateManager.MetadataWorkspace;
     ItemCollection items = null;
     if (metadataWorkspace.TryGetItemCollection(DataSpace.SSpace, out items))
     {
         var entityType = metadataWorkspace.GetItems<EntityType>(DataSpace.SSpace)
             .FirstOrDefault(t => t.Name == objectStateEntry.EntitySet.Name || t.Name + "s" == objectStateEntry.EntitySet.Name);
         if (entityType != null)
         {
             var edmProperty = entityType.Properties[propertyName];
             var facet = edmProperty.TypeUsage.Facets.Where(f => f.Name == "StoreGeneratedPattern").FirstOrDefault();
             if (facet != null)
             {
                 var facetValue = facet.Value.ToString().ToUpperInvariant();
                 returnValue = (facetValue != "NONE");
             }
         }
     }
     return returnValue;
 }
开发者ID:rickeygalloway,项目名称:Test,代码行数:33,代码来源:TrackingAuditEntity.cs


示例17: AuditEntryState

        public AuditEntryState(ObjectStateEntry objectStateEntry)
        {
            if (objectStateEntry == null)
                throw new ArgumentNullException("objectStateEntry");

            if (objectStateEntry.Entity == null)
                throw new ArgumentException("The Entity property is null for the specified ObjectStateEntry.", "objectStateEntry");

            ObjectStateEntry = objectStateEntry;
            Entity = objectStateEntry.Entity;

            EntityType = objectStateEntry.EntitySet.ElementType as EntityType;

            Type entityType = objectStateEntry.Entity.GetType();
            entityType = ObjectContext.GetObjectType(entityType);

            ObjectType = entityType;
            EntityAccessor = TypeAccessor.GetAccessor(entityType);

            AuditEntity = new AuditEntity(objectStateEntry.Entity)
            {
                Action = GetAction(objectStateEntry),
            };
        }
开发者ID:dioptre,项目名称:nkd,代码行数:24,代码来源:AuditEntryState.cs


示例18: DetermineEntityKey

        internal static Dictionary<string, object> DetermineEntityKey(ObjectStateEntry entryState)
        {
            Dictionary<string, object> key = entryState.EntityKey.EntityKeyValues.ToDictionary(kv => kv.Key, kv => kv.Value);

            if (entryState.Entity is DeviceAttachment)
            {
                key["DeviceSerialNumber"] = ((DeviceAttachment)entryState.Entity).DeviceSerialNumber;
            }
            if (entryState.Entity is DeviceCertificate)
            {
                key["DeviceSerialNumber"] = ((DeviceCertificate)entryState.Entity).DeviceSerialNumber;
            }
            if (entryState.Entity is DeviceComponent)
            {
                key["DeviceModelId"] = ((DeviceComponent)entryState.Entity).DeviceModelId;
            }
            if (entryState.Entity is DeviceUserAssignment)
            {
                key["AssignedUserId"] = ((DeviceUserAssignment)entryState.Entity).AssignedUserId;
            }
            if (entryState.Entity is JobAttachment)
            {
                key["JobId"] = ((JobAttachment)entryState.Entity).JobId;
            }
            if (entryState.Entity is JobComponent)
            {
                key["JobId"] = ((JobComponent)entryState.Entity).JobId;
            }
            if (entryState.Entity is JobLog)
            {
                key["JobId"] = ((JobLog)entryState.Entity).JobId;
            }
            if (entryState.Entity is UserAttachment)
            {
                key["UserId"] = ((UserAttachment)entryState.Entity).UserId;
            }
            if (entryState.Entity is UserFlagAssignment)
            {
                key["UserFlagId"] = ((UserFlagAssignment)entryState.Entity).UserFlagId;
                key["UserId"] = ((UserFlagAssignment)entryState.Entity).UserId;
            }

            return key;
        }
开发者ID:garysharp,项目名称:Disco,代码行数:44,代码来源:RepositoryMonitor.cs


示例19: GetDeletedEntityValues

 private static IEnumerable<Tuple<string, object, object>> GetDeletedEntityValues(ObjectStateEntry entry)
 {
     yield return Tuple.Create(string.Empty, (object)null, (object)null);
 }
开发者ID:koder05,项目名称:fogel-ba,代码行数:4,代码来源:EFExtension.cs


示例20: EventFromEntryState

        internal static RepositoryMonitorEvent EventFromEntryState(DiscoDataContext Database, DbEntityEntry entityEntry, ObjectStateEntry entryState)
        {
            RepositoryMonitorEventType eventType;
            string[] modifiedProperties = null;
            Dictionary<string, object> entityKey = null;
            Type entityType;

            switch (entryState.State)
            {
                case System.Data.EntityState.Added:
                    eventType = RepositoryMonitorEventType.Added;
                    break;
                case System.Data.EntityState.Deleted:
                    eventType = RepositoryMonitorEventType.Deleted;
                    break;
                case System.Data.EntityState.Detached:
                    eventType = RepositoryMonitorEventType.Detached;
                    break;
                case System.Data.EntityState.Modified:
                    eventType = RepositoryMonitorEventType.Modified;
                    break;
                case System.Data.EntityState.Unchanged:
                    eventType = RepositoryMonitorEventType.Unchanged;
                    break;
                default:
                    throw new NotSupportedException(string.Format("Database Entry State not supported: {0}", entryState.State.ToString()));
            }

            entityType = EntityTypeFromProxy(entryState.Entity.GetType());

            // Only pass modified properties on Modified Event
            if (eventType == RepositoryMonitorEventType.Modified)
                modifiedProperties = entryState.GetModifiedProperties().ToArray();
            else
                modifiedProperties = new string[] { }; // Empty array for Added/Deleted.

            // Don't pass entity key when entity newly added
            if (eventType != RepositoryMonitorEventType.Added)
                entityKey = DetermineEntityKey(entryState);

            return new RepositoryMonitorEvent()
            {
                EventType = eventType,
                Entity = entryState.Entity,
                EntityKey = entityKey,
                EntityType = entityType,
                ModifiedProperties = modifiedProperties,
                Database = Database,
                dbEntityState = entityEntry,
                objectEntryState = entryState
            };
        }
开发者ID:garysharp,项目名称:Disco,代码行数:52,代码来源:RepositoryMonitor.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Odbc.ODBC32类代码示例发布时间:2022-05-26
下一篇:
C# Objects.ObjectParameter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap