コード例 #1
0
ファイル: DataUpdate.cs プロジェクト: sndnvaps/Kerosene.ORM
        /// <summary>
        /// Returns an ad-hoc record containing the changes experimented by the entity since the
        /// last time its internal record was captured, or null if no changes can be detected.
        /// </summary>
        internal static IRecord GetRecordChanges(this MetaEntity meta)
        {
            object obj = meta.Entity; if (obj == null)

            {
                return(null);
            }

            if (meta.UberMap == null)
            {
                return(null);
            }
            if (meta.Record == null)
            {
                return(null);
            }

            var current = new Core.Concrete.Record(meta.UberMap.Schema);

            meta.UberMap.WriteRecord(obj, current);

            var changes = current.Changes(meta.Record); current.Dispose();

            return(changes);
        }
コード例 #2
0
        /// <summary>
        /// Generates an insert core command for the given entity, or returns null if such
        /// command cannot be generated for whatever reasons.
        /// </summary>
        internal static IInsertCommand GenerateInsertCommand(this IUberMap map, object entity)
        {
            if (entity == null)
            {
                return(null);
            }
            if (map == null || map.IsDisposed || !map.IsValidated)
            {
                return(null);
            }

            IInsertCommand cmd = null;

            int num = map.Schema.Count(x => !x.IsReadOnlyColumn);

            if (num != 0)
            {
                cmd = map.Link.Engine.CreateInsertCommand(map.Link, x => map.Table);

                var tag = new DynamicNode.Argument("x");
                var rec = new Core.Concrete.Record(map.Schema); map.WriteRecord(entity, rec);

                for (int i = 0; i < rec.Count; i++)
                {
                    if (rec.Schema[i].IsReadOnlyColumn)
                    {
                        continue;
                    }

                    var node = new DynamicNode.SetMember(tag, rec.Schema[i].ColumnName, rec[i]);
                    cmd.Columns(x => node);
                    node.Dispose();
                }

                tag.Dispose();
                rec.Dispose();
            }

            return(cmd);
        }