コード例 #1
0
        protected void UpdateRowInfoAfterUpdates(RowInfo rowInfo)
        {
            DbSetInfo dbSetInfo = rowInfo.dbSetInfo;
            var       fields    = dbSetInfo.GetFieldByNames();

            rowInfo.values.ForEach((fv) =>
            {
                FieldInfo finfo = fields[fv.fieldName];
                if (!finfo.isIncludeInResult())
                {
                    return;
                }
                string newVal;
                if (this.isEntityValueChanged(rowInfo, finfo.fieldName, out newVal))
                {
                    fv.val   = newVal;
                    fv.flags = fv.flags | ValueFlags.Refreshed;
                }
            });

            if (rowInfo.changeType == ChangeType.Added)
            {
                rowInfo.serverKey = rowInfo.GetRowKeyAsString();
            }
        }
コード例 #2
0
        public object GetTypedValue(Type entityType, DbSetInfo dbSetInfo)
        {
            FieldInfo    fi    = dbSetInfo.GetFieldByNames()[this.fieldName];
            PropertyInfo pinfo = entityType.GetProperty(fi.fieldName);

            if (pinfo == null)
            {
                throw new Exception(string.Format(ErrorStrings.ERR_PROPERTY_IS_MISSING, entityType.Name, fi.fieldName));
            }

            Type propType = pinfo.PropertyType;

            return(DataHelper.ConvertToTyped(propType, fi.dataType, fi.dateConversion, this.val));
        }
コード例 #3
0
        protected void UpdateRowInfoFromEntity(object entity, RowInfo rowInfo)
        {
            DbSetInfo dbSetInfo = rowInfo.dbSetInfo;
            var       values    = rowInfo.values;
            var       fields    = dbSetInfo.GetFieldByNames();

            values.ForEach((fv) =>
            {
                FieldInfo finfo = fields[fv.fieldName];
                if (!finfo.isIncludeInResult())
                {
                    return;
                }
                fv.val   = this.DataHelper.GetFieldValueAsString(entity, finfo.fieldName);
                fv.flags = fv.flags | ValueFlags.Refreshed;
            });

            if (rowInfo.changeType == ChangeType.Added)
            {
                rowInfo.serverKey = rowInfo.GetRowKeyAsString();
            }
        }
コード例 #4
0
        protected void UpdateEntityFromRowInfo(object entity, RowInfo rowInfo, bool isOriginal)
        {
            DbSetInfo dbSetInfo = rowInfo.dbSetInfo;
            var       values    = rowInfo.values;
            var       flds      = dbSetInfo.GetFieldByNames();

            foreach (ValueChange fv in values)
            {
                FieldInfo finfo = flds[fv.fieldName];

                if (!finfo.isIncludeInResult())
                {
                    continue;
                }
                if (isOriginal)
                {
                    if ((fv.flags & ValueFlags.Setted) == ValueFlags.Setted)
                    {
                        this.DataHelper.SetValue(entity, finfo, fv.orig);
                    }
                }
                else
                {
                    switch (rowInfo.changeType)
                    {
                    case ChangeType.Deleted:
                    {
                        //For delete fill only original values
                        if ((fv.flags & ValueFlags.Setted) == ValueFlags.Setted)
                        {
                            this.DataHelper.SetValue(entity, finfo, fv.orig);
                        }
                    }
                    break;

                    case ChangeType.Added:
                    {
                        if (finfo.isAutoGenerated)
                        {
                            continue;
                        }
                        if ((fv.flags & ValueFlags.Changed) == ValueFlags.Changed)
                        {
                            if (finfo.isReadOnly && fv.val != null && !finfo.allowClientDefault)
                            {
                                throw new DomainServiceException(string.Format(ErrorStrings.ERR_PROPERTY_IS_READONLY, finfo.fieldName));
                            }
                            if (finfo.isAutoGenerated && fv.val != null)
                            {
                                throw new DomainServiceException(string.Format(ErrorStrings.ERR_PROPERTY_IS_READONLY, finfo.fieldName));
                            }
                            this.DataHelper.SetValue(entity, finfo, fv.val);
                        }
                    }
                    break;

                    case ChangeType.Updated:
                    {
                        if ((fv.flags & ValueFlags.Changed) == ValueFlags.Changed)
                        {
                            if (finfo.isReadOnly || (finfo.isPrimaryKey > 0 || finfo.isRowTimeStamp || finfo.isAutoGenerated))
                            {
                                throw new DomainServiceException(string.Format(ErrorStrings.ERR_PROPERTY_IS_READONLY, finfo.fieldName));
                            }
                            if (!finfo.isNullable && fv.val == null)
                            {
                                throw new DomainServiceException(string.Format(ErrorStrings.ERR_FIELD_IS_NOT_NULLABLE, finfo.fieldName));
                            }
                            this.DataHelper.SetValue(entity, finfo, fv.val);
                        }
                        else if ((fv.flags & ValueFlags.Setted) == ValueFlags.Setted)
                        {
                            if ((finfo.isPrimaryKey > 0 || finfo.isRowTimeStamp || finfo.isNeedOriginal) && fv.val != fv.orig)
                            {
                                throw new DomainServiceException(string.Format(ErrorStrings.ERR_VAL_ORIGINAL_INVALID, finfo.fieldName));
                            }
                            this.DataHelper.SetValue(entity, finfo, fv.val);
                        }
                    }
                    break;
                    }
                }
            }

            if (!isOriginal && rowInfo.changeType == ChangeType.Added)
            {
                foreach (var pn in rowInfo.changeState.ParentRows)
                {
                    if (!this.DataHelper.SetProperty(entity, pn.association.childToParentName, pn.ParentRow.changeState.Entity))
                    {
                        throw new DomainServiceException(string.Format(ErrorStrings.ERR_CAN_NOT_SET_PARENT_FIELD, pn.association.childToParentName, rowInfo.dbSetInfo.EntityType.Name));
                    }
                }
            }
        }