Skip to content

Commit 8363d5f

Browse files
author
Jeff Treuting
committed
Marked EfRepository as Obsolete and removed project from solution
Changed the unit and integration tests to use the Ef5Repository where it was using EfRepository before. Made sure all unit and integration tests still passed
1 parent d456d99 commit 8363d5f

14 files changed

Lines changed: 248 additions & 339 deletions

SharpRepository.EfRepository/EfConfigRepositoryFactory.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

SharpRepository.EfRepository/EfRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace SharpRepository.EfRepository
99
/// </summary>
1010
/// <typeparam name="T">The Entity type</typeparam>
1111
/// <typeparam name="TKey">The type of the primary key.</typeparam>
12+
[Obsolete("Please upgrade to EF5 in order to use SharpRepository and Entity Framework")]
1213
public class EfRepository<T, TKey> : EfRepositoryBase<T, TKey> where T : class, new()
1314
{
1415
/// <summary>
Lines changed: 99 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,100 @@
1-
using System;
2-
using System.Data;
3-
using System.Data.Entity;
4-
using System.Linq;
5-
using SharpRepository.Repository;
6-
using SharpRepository.Repository.Caching;
7-
using SharpRepository.Repository.FetchStrategies;
8-
9-
namespace SharpRepository.EfRepository
10-
{
11-
public class EfRepositoryBase<T, TKey> : LinqRepositoryBase<T, TKey> where T : class, new()
12-
{
13-
protected IDbSet<T> DbSet { get; private set; }
14-
protected DbContext Context { get; private set; }
15-
16-
internal EfRepositoryBase(DbContext dbContext, ICachingStrategy<T, TKey> cachingStrategy = null) : base(cachingStrategy)
17-
{
18-
Initialize(dbContext);
19-
}
20-
21-
private void Initialize(DbContext dbContext)
22-
{
23-
Context = dbContext;
24-
DbSet = Context.Set<T>();
25-
}
26-
27-
protected override void AddItem(T entity)
28-
{
29-
if (typeof(TKey) == typeof(Guid) || typeof(TKey) == typeof(string))
30-
{
31-
TKey id;
32-
if (GetPrimaryKey(entity, out id) && Equals(id, default(TKey)))
33-
{
34-
id = GeneratePrimaryKey();
35-
SetPrimaryKey(entity, id);
36-
}
37-
}
38-
DbSet.Add(entity);
39-
}
40-
41-
protected override void DeleteItem(T entity)
42-
{
43-
DbSet.Remove(entity);
44-
}
45-
46-
protected override void UpdateItem(T entity)
47-
{
48-
// mark this entity as modified, in case it is not currently attached to this context
49-
Context.Entry(entity).State = EntityState.Modified;
50-
}
51-
52-
protected override void SaveChanges()
53-
{
54-
Context.SaveChanges();
55-
}
56-
57-
protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = null)
58-
{
59-
var query = DbSet.AsQueryable();
60-
return fetchStrategy == null ? query : fetchStrategy.IncludePaths.Aggregate(query, (current, path) => current.Include(path));
61-
}
62-
63-
// we override the implementation fro LinqBaseRepository becausee this is built in and doesn't need to find the key column and do dynamic expressions, etc.
64-
protected override T GetQuery(TKey key)
65-
{
66-
return DbSet.Find(key);
67-
}
68-
69-
public override void Dispose()
70-
{
71-
Dispose(true);
72-
GC.SuppressFinalize(this);
73-
}
74-
75-
protected virtual void Dispose(bool disposing)
76-
{
77-
if (!disposing) return;
78-
if (Context == null) return;
79-
80-
Context.Dispose();
81-
Context = null;
82-
}
83-
84-
private TKey GeneratePrimaryKey()
85-
{
86-
if (typeof(TKey) == typeof(Guid))
87-
{
88-
return (TKey)Convert.ChangeType(Guid.NewGuid(), typeof(TKey));
89-
}
90-
91-
if (typeof(TKey) == typeof(string))
92-
{
93-
return (TKey)Convert.ChangeType(Guid.NewGuid().ToString(), typeof(TKey));
94-
}
95-
96-
throw new InvalidOperationException("Primary key could not be generated. This only works for GUID, Int32 and String.");
97-
}
98-
}
1+
using System;
2+
using System.Data;
3+
using System.Data.Entity;
4+
using System.Linq;
5+
using SharpRepository.Repository;
6+
using SharpRepository.Repository.Caching;
7+
using SharpRepository.Repository.FetchStrategies;
8+
9+
namespace SharpRepository.EfRepository
10+
{
11+
[Obsolete("Please upgrade to EF5 in order to use SharpRepository and Entity Framework")]
12+
public class EfRepositoryBase<T, TKey> : LinqRepositoryBase<T, TKey> where T : class, new()
13+
{
14+
protected IDbSet<T> DbSet { get; private set; }
15+
protected DbContext Context { get; private set; }
16+
17+
internal EfRepositoryBase(DbContext dbContext, ICachingStrategy<T, TKey> cachingStrategy = null) : base(cachingStrategy)
18+
{
19+
Initialize(dbContext);
20+
}
21+
22+
private void Initialize(DbContext dbContext)
23+
{
24+
Context = dbContext;
25+
DbSet = Context.Set<T>();
26+
}
27+
28+
protected override void AddItem(T entity)
29+
{
30+
if (typeof(TKey) == typeof(Guid) || typeof(TKey) == typeof(string))
31+
{
32+
TKey id;
33+
if (GetPrimaryKey(entity, out id) && Equals(id, default(TKey)))
34+
{
35+
id = GeneratePrimaryKey();
36+
SetPrimaryKey(entity, id);
37+
}
38+
}
39+
DbSet.Add(entity);
40+
}
41+
42+
protected override void DeleteItem(T entity)
43+
{
44+
DbSet.Remove(entity);
45+
}
46+
47+
protected override void UpdateItem(T entity)
48+
{
49+
// mark this entity as modified, in case it is not currently attached to this context
50+
Context.Entry(entity).State = EntityState.Modified;
51+
}
52+
53+
protected override void SaveChanges()
54+
{
55+
Context.SaveChanges();
56+
}
57+
58+
protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = null)
59+
{
60+
var query = DbSet.AsQueryable();
61+
return fetchStrategy == null ? query : fetchStrategy.IncludePaths.Aggregate(query, (current, path) => current.Include(path));
62+
}
63+
64+
// we override the implementation fro LinqBaseRepository becausee this is built in and doesn't need to find the key column and do dynamic expressions, etc.
65+
protected override T GetQuery(TKey key)
66+
{
67+
return DbSet.Find(key);
68+
}
69+
70+
public override void Dispose()
71+
{
72+
Dispose(true);
73+
GC.SuppressFinalize(this);
74+
}
75+
76+
protected virtual void Dispose(bool disposing)
77+
{
78+
if (!disposing) return;
79+
if (Context == null) return;
80+
81+
Context.Dispose();
82+
Context = null;
83+
}
84+
85+
private TKey GeneratePrimaryKey()
86+
{
87+
if (typeof(TKey) == typeof(Guid))
88+
{
89+
return (TKey)Convert.ChangeType(Guid.NewGuid(), typeof(TKey));
90+
}
91+
92+
if (typeof(TKey) == typeof(string))
93+
{
94+
return (TKey)Convert.ChangeType(Guid.NewGuid().ToString(), typeof(TKey));
95+
}
96+
97+
throw new InvalidOperationException("Primary key could not be generated. This only works for GUID, Int32 and String.");
98+
}
99+
}
99100
}

SharpRepository.EfRepository/EfRepositoryConfiguration.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

SharpRepository.EfRepository/SharpRepository.EfRepository.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
<Compile Include="..\CommonAssembly.cs">
4444
<Link>Properties\CommonAssembly.cs</Link>
4545
</Compile>
46-
<Compile Include="EfRepositoryConfiguration.cs" />
47-
<Compile Include="EfConfigRepositoryFactory.cs" />
4846
<Compile Include="EfRepository.cs" />
4947
<Compile Include="EfRepositoryBase.cs" />
5048
<Compile Include="Properties\AssemblyInfo.cs" />

SharpRepository.Tests.Integration/Data/RepositoryTestCaseDataFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
using SharpRepository.Db4oRepository;
99
using SharpRepository.Tests.Integration.TestObjects;
1010
using SharpRepository.XmlRepository;
11-
using SharpRepository.EfRepository;
11+
using SharpRepository.Ef5Repository;
1212
using SharpRepository.RavenDbRepository;
13-
using SharpRepository.MongoDbRepository;
13+
using SharpRepository.MongoDbRepository;
1414
using SharpRepository.InMemoryRepository;
1515

1616
namespace SharpRepository.Tests.Integration.Data
@@ -31,12 +31,12 @@ public static IEnumerable<TestCaseData> Build(RepositoryTypes[] includeTypes)
3131
new TestCaseData(new XmlRepository<Contact, string>(xmlDataDirectoryPath)).SetName("XmlRepository Test");
3232
}
3333

34-
if (includeTypes.Contains(RepositoryTypes.Ef))
34+
if (includeTypes.Contains(RepositoryTypes.Ef5))
3535
{
3636
var dbPath = EfDataDirectoryFactory.Build();
3737
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
3838
yield return
39-
new TestCaseData(new EfRepository<Contact, string>(new TestObjectEntities("Data Source=" + dbPath))).SetName("EfRepository Test");
39+
new TestCaseData(new Ef5Repository<Contact, string>(new TestObjectEntities("Data Source=" + dbPath))).SetName("EfRepository Test");
4040
}
4141

4242
if (includeTypes.Contains(RepositoryTypes.Dbo4))

SharpRepository.Tests.Integration/RepositoryTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public enum RepositoryTypes
44
{
55
Xml,
66
InMemory,
7-
Ef,
7+
Ef5,
88
RavenDb,
99
Dbo4,
1010
MongoDb

SharpRepository.Tests.Integration/SharpRepository.Tests.Integration.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</Reference>
4040
<Reference Include="EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
4141
<SpecificVersion>False</SpecificVersion>
42-
<HintPath>..\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll</HintPath>
42+
<HintPath>..\SharpRepository.Ef5Repository\bin\Release\EntityFramework.dll</HintPath>
4343
</Reference>
4444
<Reference Include="Esent.Interop">
4545
<HintPath>..\packages\RavenDB-Embedded.1.0.888\lib\net40\Esent.Interop.dll</HintPath>
@@ -162,9 +162,9 @@
162162
<Project>{12DD3830-5A12-484C-98B4-D30811DEC8A9}</Project>
163163
<Name>SharpRepository.Db4oRepository</Name>
164164
</ProjectReference>
165-
<ProjectReference Include="..\SharpRepository.EfRepository\SharpRepository.EfRepository.csproj">
166-
<Project>{DAFB3EB8-A771-4CC5-9375-E56F0DED60D6}</Project>
167-
<Name>SharpRepository.EfRepository</Name>
165+
<ProjectReference Include="..\SharpRepository.Ef5Repository\SharpRepository.Ef5Repository.csproj">
166+
<Project>{7acc7e0f-2eb9-45e1-8841-a00a40bcf0b5}</Project>
167+
<Name>SharpRepository.Ef5Repository</Name>
168168
</ProjectReference>
169169
<ProjectReference Include="..\SharpRepository.InMemoryRepository\SharpRepository.InMemoryRepository.csproj">
170170
<Project>{13AD3FCA-4C9D-4674-B786-F30843638D3B}</Project>

SharpRepository.Tests.Integration/TestAttributes/ExecuteForAllRepositoriesAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private static IEnumerable<TestCaseData> ForAllRepositoriesTestCaseData
1515
RepositoryTypes.Xml,
1616
RepositoryTypes.MongoDb,
1717
RepositoryTypes.InMemory,
18-
RepositoryTypes.Ef,
18+
RepositoryTypes.Ef5,
1919
}); }
2020
}
2121

SharpRepository.Tests/App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<sharpRepository>
1515
<repositories default="inMemory">
1616
<repository name="inMemory" factory="SharpRepository.InMemoryRepository.InMemoryConfigRepositoryFactory, SharpRepository.InMemoryRepository" />
17-
<repository name="efRepos" factory="SharpRepository.EfRepository.EfConfigRepositoryFactory, SharpRepository.EfRepository" connectionString="EfConnectionString" dbContextType="SharpRepository.Tests.TestObjects.TestObjectEntities, SharpRepository.Tests" cachingStrategy="timeout"/>
17+
<repository name="ef5Repos" factory="SharpRepository.Ef5Repository.Ef5ConfigRepositoryFactory, SharpRepository.Ef5Repository" connectionString="EfConnectionString" dbContextType="SharpRepository.Tests.TestObjects.TestObjectEntities, SharpRepository.Tests" cachingStrategy="timeout"/>
1818

1919
<repository name="inMemoryNoCaching" factory="SharpRepository.InMemoryRepository.InMemoryConfigRepositoryFactory, SharpRepository.InMemoryRepository" cachingStrategy="none" />
2020
</repositories>
@@ -32,7 +32,7 @@
3232

3333
<sharpRepository2>
3434
<repositories>
35-
<repository name="ef" factory="SharpRepository.EfRepository.EfConfigRepositoryFactory, SharpRepository.EfRepository" connectionString="EfConnectionString" dbContextType="SharpRepository.Tests.TestObjects.TestObjectEntities, SharpRepository.Tests" />
35+
<repository name="ef" factory="SharpRepository.Ef5Repository.Ef5ConfigRepositoryFactory, SharpRepository.Ef5Repository" connectionString="EfConnectionString" dbContextType="SharpRepository.Tests.TestObjects.TestObjectEntities, SharpRepository.Tests" />
3636
<repository name="inMem" factory="SharpRepository.InMemoryRepository.InMemoryConfigRepositoryFactory, SharpRepository.InMemoryRepository" />
3737
</repositories>
3838
</sharpRepository2>

0 commit comments

Comments
 (0)