日期:2014-05-20  浏览次数:20853 次

LINQ返回的ObjectSet<T>集合是不可以修改的么?
public ObjectSet<OtherFolder> OtherFolders
        {
            get
            {
                if ((_OtherFolders == null))
                {
                    _OtherFolders = base.CreateObjectSet<OtherFolder>("OtherFolders");
                }
                foreach (var o in _OtherFolders) 
                {
                    o.FolderName = "s";
                }
                this.SaveChanges();
                return _OtherFolders;
            }
        }
------解决方案--------------------
依然可以修改:

            using (BirthdayRemindEntities2 db = new BirthdayRemindEntities2())
            {
                System.Data.Objects.ObjectSet<car> orders = db.CreateObjectSet<car>();
                foreach (car item in orders)
                {
                    item.proname = item.proname + item.ID;
                }
                db.SaveChanges();

                foreach (car item in orders)
                    item.type = item.type + item.ID;

                db.SaveChanges();
             }

------解决方案--------------------
public class ObjectSet<TEntity> : ObjectQuery<TEntity>, 
IObjectSet<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>, 
IQueryable, IEnumerable
where TEntity : class


可以修改的,从它的继承类上就可以看的出来

Represents a typed entity set that is used to perform create, read, update, and delete operations.