Note that there are some explanatory texts on larger screens.

plurals
  1. POExtend System.Data.Objects 3.5 methods for 4.0 (such as IObjectSet, CreateObjectSet,ContextOptions
    primarykey
    data
    text
    <p>I am trying to extend the System.Data.Objects 3.5 version to include some System.Data.Objects .Net 4.0 methods (such as IObjectSet, CreateObjectSet,ContextOptions). I am forced to target 3.5 in a Sharepoint 2010 project, using EF v 1. My Repository was built in .Net 4.0, shown below. How can I either correct this to work in 3.5, or extend the System.Data.Objects 3.5 class so that the new 4.0 methods will be consumed:</p> <pre><code>using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Data.Objects; using System.Linq.Expressions; using System.Data; using System.Data.Objects.DataClasses; using Workflowportal_LINQDAL.Repository.Interface; using Workflowportal_LINQDAL.Repository.Specification; namespace Workflowportal_LINQDAL.Repository.Repository { public class Repository&lt;TEntity&gt; : IRepository&lt;TEntity&gt; where TEntity : class { private ObjectContext _context; private readonly IObjectSet&lt;TEntity&gt; _objectSet; public Repository(ObjectContext context) { _context = context; _objectSet = _context.CreateObjectSet&lt;TEntity&gt;(); //_context.ContextOptions.LazyLoadingEnabled = true; Default! } public Repository(ObjectContext context, bool lazyLoading) { _context = context; _objectSet = _context.CreateObjectSet&lt;TEntity&gt;(); _context.ContextOptions.LazyLoadingEnabled = lazyLoading; } public void SaveChanges() { _context.SaveChanges(); } //public void SaveChanges(SaveOptions options) //{ // _context.SaveChanges(options); //} public void AcceptAllChanges() { _context.AcceptAllChanges(); } public void Add(TEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } _objectSet.AddObject(entity); } public void Edit(TEntity entity) { _objectSet.Attach(entity); _context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); } public void Delete(TEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } _objectSet.DeleteObject(entity); } public void Delete(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate) { var records = Find(predicate); foreach (var record in records) { Delete(record); } } public void Delete(ISpecification&lt;TEntity&gt; specification) { throw new NotImplementedException(); } public void DeleteRelatedEntities(TEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } var releatedEntities = ((IEntityWithRelationships)entity).RelationshipManager.GetAllRelatedEnds().SelectMany( e =&gt; e.CreateSourceQuery().OfType&lt;TEntity&gt;()).ToList(); foreach (var releatedEntity in releatedEntities) { _objectSet.DeleteObject(releatedEntity); } _objectSet.DeleteObject(entity); } public IEnumerable&lt;TEntity&gt; GetAll() { return _objectSet.AsEnumerable(); } public IQueryable&lt;TEntity&gt; GetAllQuery() { return _objectSet.AsQueryable(); } public IEnumerable&lt;TEntity&gt; GetAllPaged(int page, int pageSize) { return _objectSet.AsEnumerable().Skip(pageSize).Take(page); } public IEnumerable&lt;TEntity&gt; Find(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate) { return _objectSet.Where(predicate).AsEnumerable(); } public IQueryable&lt;TEntity&gt; FindQuery(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate) { return _objectSet.Where(predicate).AsQueryable(); } public IEnumerable&lt;TEntity&gt; Find(ISpecification&lt;Func&lt;TEntity, bool&gt;&gt; specification) { throw new NotImplementedException(); } public IEnumerable&lt;TEntity&gt; FindPaged(int page, int pageSize, Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate) { return _objectSet.Where(predicate).Skip(pageSize).Take(page).AsEnumerable(); } public TEntity Single(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate) { return _objectSet.SingleOrDefault(predicate); } public TEntity Single(ISpecification&lt;Func&lt;TEntity, bool&gt;&gt; specification) { throw new NotImplementedException(); } public TEntity First(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate) { return _objectSet.FirstOrDefault(predicate); } public TEntity First(ISpecification&lt;Func&lt;TEntity, bool&gt;&gt; specification) { throw new NotImplementedException(); } public int Count() { return _objectSet.Count(); } public int Count(Expression&lt;Func&lt;TEntity, bool&gt;&gt; criteria) { return _objectSet.Count(criteria); } public int Count(ISpecification&lt;TEntity&gt; specification) { throw new NotImplementedException(); } #region IDisposable public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!disposing) return; if (_context == null) return; _context.Dispose(); _context = null; } #endregion } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload