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


C# EntityState.ToString方法代码示例

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


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

示例1: FlightVersionHistory

        /// <summary>
        /// Initializes a new instance of the <see cref="FlightVersionHistory"/> class.
        /// </summary>
        /// <param name="flight">
        /// The flight.
        /// </param>
        /// <param name="entityState">
        /// The entity state.
        /// </param>
        public FlightVersionHistory(Flight f, EntityState entityState)
        {
            this.State = entityState.ToString();

            this.FlightId = f.FlightId;
            this.Created = DateTime.Now;
            this.Deleted = f.Deleted;
            this.LastUpdated = f.LastUpdated;
            this.LastUpdatedBy = f.LastUpdatedBy;
            this.Description = f.Description;

            this.Date = f.Date;
            this.Departure = f.Departure;
            this.Landing = f.Landing;
            this.LandingCount = f.LandingCount;
            this.PlaneId = f.PlaneId;
            this.PilotId = f.PilotId;
            this.PilotBackseatId = f.PilotBackseatId;
            this.BetalerId = f.BetalerId;
            this.StartTypeId = f.StartTypeId;
            this.StartedFromId = f.StartedFromId;
            this.LandedOnId = f.LandedOnId;
            this.TachoDeparture = f.TachoDeparture;
            this.TachoLanding = f.TachoLanding;
        }
开发者ID:janhebnes,项目名称:startlist.club,代码行数:34,代码来源:FlightVersionHistory.cs

示例2: GetAuditLogs

        private static IEnumerable<CustomAuditLog> GetAuditLogs(EntityEntry entityEntry, string userName, EntityState entityState)
        {
            var returnValue = new List<CustomAuditLog>();
            // var keyRepresentation = BuildKeyRepresentation(entityEntry, KeySeperator);
            DateTime RightNow = DateTime.Now;
            Guid AuditBatchID;
            UuidCreateSequential(out AuditBatchID);

            var auditedPropertyNames =
                entityEntry.Entity.GetType()
                    .GetProperties().Where(p => !p.GetCustomAttributes(typeof(DoNotAudit), true).Any())
                    .Select(info => info.Name);

            var differences = new List<PropertyDiff>();

            foreach (var propertyEntry in entityEntry.Metadata.GetProperties()
                           .Where(x => auditedPropertyNames.Contains(x.Name))
                           .Select(property => new { PropertyName = property.Name, Property = entityEntry.Property(property.Name) }))
            {
                var originalValue = Convert.ToString(propertyEntry.Property.OriginalValue);
                var currentValue = Convert.ToString(propertyEntry.Property.CurrentValue);

                if (entityState == EntityState.Modified && originalValue == currentValue) //Values are the same, don't log
                    continue;

                var diff = new PropertyDiff { PropertyName = propertyEntry.PropertyName, OriginalValue = originalValue, NewValue = currentValue } ;
                differences.Add(diff);

            }
            var ser = JsonConvert.SerializeObject(differences);

            returnValue.Add(new CustomAuditLog
            {
                Differences = ser,
                EventDateTime = RightNow,
                EventType = entityState.ToString(),
                UserName = userName,
                TableName = entityEntry.Entity.GetType().Name
            });
            return returnValue;
        }
开发者ID:oconics,项目名称:EFAuditing,代码行数:41,代码来源:CustomAuditLogBuilder.cs

示例3: GetAuditLogs

        private static IEnumerable<AuditLog> GetAuditLogs(EntityEntry entityEntry, string userName, EntityState entityState)
        {
            var returnValue = new List<AuditLog>();
            var keyRepresentation = BuildKeyRepresentation(entityEntry, KeySeperator);

            var auditedPropertyNames =
                entityEntry.Entity.GetType()
                    .GetProperties().Where(p => !p.GetCustomAttributes(typeof (DoNotAudit), true).Any())
                    .Select(info => info.Name);
            foreach (var propertyEntry in entityEntry.Metadata.GetProperties()
                .Where(x => auditedPropertyNames.Contains(x.Name))
                .Select(property => entityEntry.Property(property.Name)))
            {
                if(entityState == EntityState.Modified)
                    if (Convert.ToString(propertyEntry.OriginalValue) == Convert.ToString(propertyEntry.CurrentValue)) //Values are the same, don't log
                        continue;
                returnValue.Add(new AuditLog
                {
                    KeyNames = keyRepresentation.Key,
                    KeyValues = keyRepresentation.Value,
                    OriginalValue = entityState != EntityState.Added
                        ? Convert.ToString(propertyEntry.OriginalValue)
                        : null,
                    NewValue = entityState == EntityState.Modified || entityState == EntityState.Added
                        ? Convert.ToString(propertyEntry.CurrentValue)
                        : null,
                    ColumnName = propertyEntry.Metadata.Name,
                    EventDateTime = DateTime.Now,
                    EventType = entityState.ToString(),
                    UserName = userName,
                    TableName = entityEntry.Entity.GetType().Name
                });
            }
            return returnValue;
        }
开发者ID:johannbrink,项目名称:EFAuditing,代码行数:35,代码来源:AuditLogBuilder.cs

示例4: GetAuditLogs

        private static IEnumerable<AuditLog> GetAuditLogs(DbEntityEntry entityEntry, string userName, EntityState entityState, ObjectContext objectContext,
            DateTime auditDateTime)
        {
            var returnValue = new List<AuditLog>();
            var keyRepresentation = BuildKeyRepresentation(entityEntry, KeySeperator, objectContext);

            var auditedPropertyNames = GetDeclaredPropertyNames(entityEntry.Entity.GetType(), objectContext.MetadataWorkspace);
            foreach (var propertyName in auditedPropertyNames)
            {
                var currentValue = Convert.ToString(entityEntry.CurrentValues.GetValue<object>(propertyName));
                var originalValue = Convert.ToString(entityEntry.GetDatabaseValues().GetValue<object>(propertyName));
                if (entityState == EntityState.Modified)
                    if (originalValue == currentValue) //Values are the same, don't log
                        continue;
                returnValue.Add(new AuditLog
                {
                    KeyNames = keyRepresentation.Key,
                    KeyValues = keyRepresentation.Value,
                    OriginalValue = entityState != EntityState.Added
                        ? originalValue
                        : null,
                    NewValue = entityState == EntityState.Modified || entityState == EntityState.Added
                        ? currentValue
                        : null,
                    ColumnName = propertyName,
                    EventDateTime = auditDateTime,
                    EventType = entityState.ToString(),
                    UserName = userName,
                    TableName = entityEntry.Entity.GetType().Name
                });
            }
            return returnValue;
        }
开发者ID:johannbrink,项目名称:EF6Auditing,代码行数:33,代码来源:AuditLogBuilder.cs

示例5: StateEntry2OperationLog

        /// <summary>
        /// States the entry2 operation log.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="createdDate">The createdDate.</param>
        /// <param name="objectId">The key value.</param>
        /// <param name="state">The state.</param>
        /// <returns>
        /// OperationLog object
        /// </returns>
        private OperationLogEntity StateEntry2OperationLog(string objectType, DateTime createdDate, string objectId, EntityState state)
        {
            var retVal = new OperationLogEntity
            {
                Id = Guid.NewGuid().ToString("N"),
                CreatedDate = createdDate,
                ObjectId = objectId,
                ObjectType = objectType,
                CreatedBy = CurrentPrincipal.GetCurrentUserName(),
                OperationType = state.ToString()
            };

            return retVal;
        }
开发者ID:adwardliu,项目名称:vc-community,代码行数:24,代码来源:ChangeLogInterceptor.cs

示例6: VerifyData

        public static void VerifyData(Workspace w, Hashtable entities, Hashtable entitiesAfter)
        {
            IDictionaryEnumerator _enum = entities.GetEnumerator();
            object _entity = null;
            EntityStates _state = EntityStates.Unchanged;
            string _uri = null;

            while (_enum.MoveNext())
            {
                _entity = _enum.Key;
                _state = (EntityStates)Enum.Parse(typeof(EntityStates), (string)((string[])_enum.Value)[0], true);

                switch (_state)
                {
                    case EntityStates.Added:
                        if (entitiesAfter != null)
                        {
                            _uri = (string)((string[])entitiesAfter[_entity])[1];
                            Verify(_entity, _uri, _state, w);
                            AstoriaTestLog.WriteLineIgnore("Verified entity " + _entity.GetType().Name + " was inserted!");
                        }
                        break;
                    case EntityStates.Unchanged:
                    case EntityStates.Modified:
                        _uri = (string)((string[])_enum.Value)[1];
                        Verify(_entity, _uri, _state, w);
                        AstoriaTestLog.WriteLineIgnore("Verified entity " + _entity.GetType().Name + " was " + _state.ToString().ToLower());
                        break;
                    case EntityStates.Deleted:
                        try
                        {
                            _uri = (string)((string[])_enum.Value)[1];
                            Verify(_entity, _uri, _state, w);
                        }
                        catch (Exception e)
                        {
                            if (e.InnerException is DataServiceQueryException)
                                AstoriaTestLog.WriteLineIgnore("Verified entity " + _entity.GetType().Name + " was " + _state.ToString().ToLower());
                            else
                                AstoriaTestLog.FailAndContinue(e);
                        }
                        break;
                }

            }





        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:51,代码来源:UpdateModel.cs

示例7: StateEntry2OperationLog

        /// <summary>
        /// States the entry2 operation log.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="createdDate">The createdDate.</param>
        /// <param name="objectId">The key value.</param>
        /// <param name="state">The state.</param>
        /// <returns>
        /// OperationLog object
        /// </returns>
        private OperationLogEntity StateEntry2OperationLog(string objectType, DateTime createdDate, string objectId, EntityState state)
        {
            var retVal = new OperationLogEntity
            {
                ObjectId = objectId,
                ObjectType = objectType,
                OperationType = state.ToString()
            };

            return retVal;
        }
开发者ID:lorenzonet,项目名称:vc-community,代码行数:21,代码来源:ChangeLogInterceptor.cs


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