Exemple #1
0
        /// <summary>
        ///     Checks the Row version of the local entry and the server on
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>True when the version is Equals, otherwise false</returns>
        private bool CheckRowVersion <T>(T entry)
        {
            var type       = GetClassInfo(typeof(T));
            var rowVersion =
                GetClassInfo(entry
                             .GetType())
                .RowVersionProperty;

            if (rowVersion != null)
            {
                var rowversionValue = rowVersion.GetConvertedValue(entry) as byte[];
                if (rowversionValue != null ||
                    entry.GetPK(Config) == DataConverterExtensions.GetDefault(type.PrimaryKeyProperty.PropertyType))
                {
                    var rowVersionprop   = type.GetLocalToDbSchemaMapping(rowVersion.PropertyName);
                    var staticRowVersion = "SELECT " + rowVersionprop + " FROM " + type.TableName + " WHERE " +
                                           type.GetPK(Config) + " = " + entry.GetPK(Config);

                    var skalar = Database.GetSkalar(staticRowVersion);
                    if (skalar == null)
                    {
                        return(false);
                    }
                    return(((byte[])skalar).SequenceEqual(rowversionValue));
                }
                return(false);
            }
            return(false);
        }
        /// <summary>
        ///     Checks the Row version of the local entry and the server on
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>True when the version is Equals, otherwise false</returns>
        private bool CheckRowVersion <T>(T entry)
        {
            var type       = GetClassInfo(typeof(T));
            var rowVersion =
                GetClassInfo(entry
                             .GetType())
                .RowVersionProperty;

            if (rowVersion == null)
            {
                return(false);
            }

            if (type.PrimaryKeyProperty == null)
            {
                throw new InvalidOperationException("This Operation requires and Primary Key attribute on the entity to succeed");
            }

            var rowversionValue = rowVersion.GetConvertedValue(entry) as byte[];

            if (rowversionValue == null && entry.GetPK(Config) !=
                DataConverterExtensions.GetDefault(type.PrimaryKeyProperty.PropertyType))
            {
                return(false);
            }

            var rowVersionprop   = type.GetLocalToDbSchemaMapping(rowVersion.PropertyName);
            var staticRowVersion = "SELECT " + rowVersionprop + " FROM " + type.TableName + " WHERE " +
                                   type.PrimaryKeyProperty.DbName + " = " + entry.GetPK(Config);

#pragma warning disable 618
            var skalar = Database.GetSkalar(staticRowVersion);
#pragma warning restore 618
            if (skalar == null)
            {
                return(false);
            }
            return(((byte[])skalar).SequenceEqual(rowversionValue));
        }