コード例 #1
0
        protected static System.Data.Linq.EntitySet <TEntity> Detach <TEntity>(System.Data.Linq.EntitySet <TEntity> set, Action <TEntity> onAdd, Action <TEntity> onRemove)
            where TEntity : LinqEntityBase
        {
            if (set == null || !set.HasLoadedOrAssignedValues)
            {
                return(new System.Data.Linq.EntitySet <TEntity>(onAdd, onRemove));
            }

            // copy list and detach all entities
            var list = set.ToList();

            list.ForEach(t => t.Detach());

            var newSet = new System.Data.Linq.EntitySet <TEntity>(onAdd, onRemove);

            newSet.Assign(list);
            return(newSet);
        }
コード例 #2
0
        protected static System.Data.Linq.EntitySet <TEntity> Detach <TEntity>(System.Data.Linq.EntitySet <TEntity> set, Action <TEntity> onAdd, Action <TEntity> onRemove)
            where TEntity : LinqEntityBase
        {
            if (set == null || !set.HasLoadedOrAssignedValues)
            {
                return(new System.Data.Linq.EntitySet <TEntity>(onAdd, onRemove));
            }

            // make sure that no lazy loading happens.
            System.Reflection.FieldInfo field = set.GetType().GetField("isLoaded", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            field.SetValue(set, true);

            // copy list and detach all entities
            var list = set.ToList();

            list.ForEach(t => t.Detach());

            var newSet = new System.Data.Linq.EntitySet <TEntity>(onAdd, onRemove);

            newSet.Assign(list);
            return(newSet);
        }