-
Notifications
You must be signed in to change notification settings - Fork 0
/
RepositoryPattern.txt
761 lines (606 loc) · 25.2 KB
/
RepositoryPattern.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using EntityFramework.Extensions;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Core.Mapping;
using System.Data.Entity.Core.Objects;
namespace Library.Core.Data
{
/// <summary>
/// Generic Repository Default-Implementation
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public class Repository<TEntity, TContext> : IRepository<TEntity>
where TContext : DbContext
where TEntity : class
{
protected DbSet<TEntity> dbSet;
protected TContext db;
public Repository(DbContext dbContext)
{
db = dbContext as TContext;
dbSet = db.Set<TEntity>();
}
#region IRepository<T> Members
/// <summary>
/// Generate & get next-Id-value for new-entity
/// </summary>
/// <returns></returns>
public long GetNextId()
{
//string sql = "SELECT NEXT VALUE FOR dbo.Sequence_User_UserId";
string tableName = GetT_TableName();
string sequenceName = "Sequence_" + tableName + "_" + tableName + "Id";
return GenerateNextId(sequenceName);
}
/// <summary>
/// Add an entity to the EF - [without saving them to database immediately]
/// </summary>
/// <param name="entity"></param>
public void Add(TEntity entity)
{
dbSet.Add(entity);
//return DbSet.Add(entity);
//var newEntry = db.Set<T>().Add(entity);
//db.SaveChanges();
//return newEntry;
}
/// <summary>
/// Add list of entities to the EF - [without saving them to database immediately]
/// </summary>
/// <param name="entities"></param>
public void Add(IEnumerable<TEntity> entities)
{
foreach (var entity in entities)
this.Add(entity);
//{
// db.Set<T>().Add(entity);
//}
//db.SaveChanges();
}
/// <summary>
/// Remove an entity from EF - [without saving them to database immediately]
/// </summary>
/// <param name="entity"></param>
public void Remove(TEntity entity)
{
dbSet.Remove(entity);
}
/// <summary>
/// Update an entity in EF - [without saving them to database immediately]
/// </summary>
/// <param name="entity"></param>
public void Update(TEntity entity)
{
var entry = db.Entry(entity);
db.Set<TEntity>().Attach(entity);
entry.State = EntityState.Modified;
//dbSet.Attach(entity);
//db.SaveChanges();
}
#region Search Entities
/// <summary>
/// Find entity by ID
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public TEntity GetById(long id)
{
return dbSet.Find(id);
}
//public T GetById(int id)
//{
// return dbSet.Find(id);
//}
public TEntity Get(Expression<Func<TEntity, bool>> filter = null, string includingProperties = null)
{
IQueryable<TEntity> query = dbSet;
if (filter != null)
{
query = query.Where(filter);
}
if (includingProperties != null)
{
foreach (var includeproperty in includingProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeproperty);
}
}
return query.AsQueryable().FirstOrDefault();
}
public int Count()
{
return dbSet.Count();
}
public int Count(Expression<Func<TEntity, bool>> predeciate)
{
return dbSet.Count(predeciate);
}
/// <summary>
/// Search entities
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public IQueryable<TEntity> Search(Expression<Func<TEntity, bool>> wherePredicate)
{
return dbSet.Where(wherePredicate);
}
/// <summary>
/// Get All entities in database
/// </summary>
/// <returns></returns>
public virtual IQueryable<TEntity> GetAll()
{
return dbSet;
}
public virtual IQueryable<TEntity> GetAll(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderyby = null, string includingProperties = null)
{
IQueryable<TEntity> query = dbSet;
if (filter != null)
{
query = query.Where(filter);
}
if (includingProperties != null)
{
foreach (var includeproperty in includingProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeproperty);
}
}
if (orderyby != null)
{
return orderyby(query).AsQueryable();
}
else
{
return query.AsQueryable();
}
}
/// <summary>
/// Get DbSet reference to write your custom LINQ
/// </summary>
/// <returns></returns>
public IQueryable<TEntity> GetDbSet()
{
return dbSet;
}
#endregion
#region Paging - Parameterized
/// <summary>
/// Get First-Page data (0-first page)
/// </summary>
/// <returns></returns>
public IQueryable<TEntity> GetFirstPage()
{
return dbSet.Take(() => pageSize);
// Hint: Below lines are not parameterized by EF
// ---------------------------------------------
//return dbSet.Take(10);
//return dbSet.Take(pageSize);
}
public IQueryable<TEntity> GetFirstPage(string sorPropertyName, bool ascending = true)
{
return OrderByFieldForPaging(sorPropertyName, ascending).Take(() => pageSize);
// Hint: Below lines are not parameterized by EF
// ---------------------------------------------
//return dbSet.Take(10);
//return dbSet.Take(pageSize);
}
/// <summary>
/// Get Next-Page data
/// </summary>
/// <param name="currentPageNo"></param>
/// <param name="newPageNo"></param>
/// <returns></returns>
public IQueryable<TEntity> GetNextPage(int currentPageNo, out int newPageNo)
{
int skips = util_GetSkipsForThisPage(currentPageNo + 1, out newPageNo);
return OrderByFieldForPaging().Skip(() => skips).Take(() => pageSize);
//return dbSet.OrderBy(...).Skip(() => skips).Take(() => pageSize);
}
public IQueryable<TEntity> GetNextPage(int currentPageNo, out int newPageNo, string sorPropertyName, bool ascending = true)
{
int skips = util_GetSkipsForThisPage(currentPageNo + 1, out newPageNo);
return OrderByFieldForPaging(sorPropertyName, ascending).Skip(() => skips).Take(() => pageSize);
//return dbSet.OrderBy(...).Skip(() => skips).Take(() => pageSize);
}
public IQueryable<TEntity> GetNextPage(int currentPageNo, out int newPageNo, string includingProperties = null)
{
int skips = util_GetSkipsForThisPage(currentPageNo + 1, out newPageNo);
return OrderByFieldForPaging().Skip(() => skips).Take(() => pageSize);
//return dbSet.OrderBy(...).Skip(() => skips).Take(() => pageSize);
}
/// <summary>
/// Get Previous-Page data
/// </summary>
/// <param name="currentPageNo"></param>
/// <param name="newPageNo"></param>
/// <returns></returns>
public IQueryable<TEntity> GetPreviousPage(int currentPageNo, out int newPageNo)
{
int skips = util_GetSkipsForThisPage(currentPageNo - 1, out newPageNo);
return OrderByFieldForPaging().Skip(() => skips).Take(() => pageSize);
//return dbSet.OrderBy(...).Skip(() => skips).Take(() => pageSize);
}
public IQueryable<TEntity> GetPreviousPage(int currentPageNo, out int newPageNo, string sorPropertyName, bool ascending = true)
{
int skips = util_GetSkipsForThisPage(currentPageNo - 1, out newPageNo);
return OrderByFieldForPaging(sorPropertyName, ascending).Skip(() => skips).Take(() => pageSize);
//return dbSet.OrderBy(...).Skip(() => skips).Take(() => pageSize);
}
/// <summary>
/// Get Last-Page data
/// </summary>
/// <param name="lastPageNo"></param>
/// <returns></returns>
public IQueryable<TEntity> GetLastPage(out int lastPageNo)
{
int skips = util_GetSkipsForLastPage(out lastPageNo);
return OrderByFieldForPaging().Skip(() => skips).Take(() => pageSize);
//return dbSet.OrderBy(...).Skip(() => skips).Take(() => pageSize);
}
public IQueryable<TEntity> GetLastPage(out int lastPageNo, string sorPropertyName, bool ascending = true)
{
int skips = util_GetSkipsForLastPage(out lastPageNo);
return OrderByFieldForPaging(sorPropertyName, ascending).Skip(() => skips).Take(() => pageSize);
//return dbSet.OrderBy(...).Skip(() => skips).Take(() => pageSize);
}
// TODO: Get from database app-preferences
int pageSize = 10;
#endregion
#region Batch Operations
/// <summary>
/// Batch Delete operation - [executed immediately to database] Example: (u => u.UserName == null )
/// </summary>
/// <param name="wherePredicate"></param>
/// <returns></returns>
public int BatchDelete(Expression<Func<TEntity, bool>> wherePredicate)
{
return dbSet.Where(wherePredicate).Delete();
}
/// <summary>
/// Batch Delete operation, by providing list of Ids - [executed immediately to database]
/// </summary>
/// <param name="ids"></param>
public void BatchDelete(List<long> ids)
{
string tableName = GetT_TableName();
string primaryKey = GetT_TableKeyColumnName();
var totalCount = ids.Count;
if (totalCount == 0)
{
return;
}
var chunks = CreateChunksOfIds(ids, 2000);
foreach (var key in chunks.Keys)
{
var thisChunk = chunks[key];
var countChunk = thisChunk.Count;
var sb = new StringBuilder();
sb.Append("Delete from [");
sb.Append(tableName);
sb.Append("] Where ");
sb.Append(primaryKey);
sb.Append(" IN (");
for (int i = 0; i < countChunk; i++)
{
if (i > 0)
{
sb.Append(",");
}
sb.Append(thisChunk[i]);
}
sb.Append(")");
db.Database.ExecuteSqlCommand(sb.ToString());
}
}
/// <summary>
/// Batch Update operation - [executed immediately to database]
/// Example: (u => u.EmailAddress.EndsWith("@insight.com.au"), new User { EmailAddress = "@my-insight.com.au" } )
/// </summary>
/// <param name="wherePredicate"></param>
/// <param name="updateExpression"></param>
/// <returns></returns>
public int BatchUpdate(Expression<Func<TEntity, bool>> wherePredicate, Expression<Func<TEntity, TEntity>> updateExpression)
{
return dbSet.Where(wherePredicate).Update(updateExpression);
}
/// <summary>
/// Batch Insert operation, by providing list-of-entities - [executed immediately to database]
/// STATUS: in-progress - initially entity.properties will be supported, later child entities like User.UserDetail will be supported to n-nested-level
/// </summary>
/// <param name="entities"></param>
void BatchInsert_InProgress(List<TEntity> entities)
{
if (entities == null || entities.Count <= 0)
return;
var columns = GetT_TableColumnsList();
StringBuilder sb = new StringBuilder();
List<string> sqlChunks = new List<string>();
int chunkLengthLimit = 2000; //TODO: from
foreach (var entity in entities)
{
if (sb.Length <= 0)
{
sb.Append("INSERT INTO (col1, col2...)");
foreach (var col in columns)
{
}
sb.Append(") ");
}
//if(sb.Length <= 0 || sb.Length >= )
// 1. create INSERT INTO (col1, col2, ...)
// 2. create SELECT col1Value, col2Value, ...
// 3. UNION ALL - if next row exists
}
}
#endregion
#endregion
#region Utility Methods
/// <summary>
/// TODO: 1. Change return type int to long
/// 2. In Database set Ids to bingint instead int
/// </summary>
/// <param name="sequenceName">name of sequence</param>
/// <returns></returns>
protected long GenerateNextId(string sequenceName)
{
string sql = "SELECT NEXT VALUE FOR dbo." + sequenceName;
var id = dbSet.GetContext().ExecuteStoreQuery<long>(sql).First();
return id;// (int)id;
// NOTE: Always use "long or int" not "mixed" throughout domain databases, otherwise, exception will be raised
// Exception: "The specified cast from a materialized 'System.Int32' type to the 'System.Int64' type is not valid."
// Issue: "The underlying provider failed on Open."
// Article: http://stackoverflow.com/questions/2475008/the-underlying-provider-failed-on-open
// Guess: potential reason is MSDTC not installed
// Resolved: by running MSDTC service on windows-7
//string sql = "SELECT NEXT VALUE FOR dbo.Sequence_User_UserId";
//string tableName = GetTableName(typeof(T), db);
//string sql = "SELECT NEXT VALUE FOR dbo.Sequence_" + tableName + "_" + tableName + "Id";
}
int util_GetSkipsForFirstPage()
{
return 0;
}
int util_GetSkipsForThisPage(int pageNo, out int newPageNo)
{
newPageNo = pageNo;
if (pageNo <= 0)
return util_GetSkipsForFirstPage();
int allPagesCount = util_GetTotalPagesCount();
if (pageNo > allPagesCount)
return util_GetSkipsForLastPage(out newPageNo, allPagesCount);
return pageNo * pageSize;
//return (pageNo - 1) * pageSize;
}
int util_GetSkipsForLastPage(out int newPageNo, int allPagesCount = -1)
{
newPageNo = allPagesCount;
if (allPagesCount < 0)
allPagesCount = util_GetTotalPagesCount();
newPageNo = allPagesCount;
if (allPagesCount <= 0)
return 0;
// 101 = 11 -> (11 - 1) * 10 = 100 skips
// 100 = 10 -> (10 - 1) * 10 = 90 skips
return (allPagesCount - 1) * pageSize;
}
int util_GetTotalPagesCount()
{
int totalCount = util_GetAllCount();
// min pageSize = 10, max pageSize = 1000;
if (pageSize < 10)
pageSize = 10;
if (pageSize > 1000)
pageSize = 1000;
// 0/10 = 0, 100/10 = 10, 101/10 = 10+1
int pagesCount = (totalCount > 0) ? totalCount / pageSize : 0; // +1; // 0/10 = 0 + 1
if (totalCount > pageSize && totalCount % pageSize > 0)
pagesCount++;
return pagesCount;
}
int util_GetAllCount()
{
return dbSet.Count();
}
// Issue: "The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'."
// http://romiller.com/2014/04/08/ef6-1-mapping-between-types-tables/
public string GetT_TableName() //Type type, DbContext context)
{
var table = GetT_Table_EntitySet(typeof(TEntity), db);
return (string)table.MetadataProperties["Table"].Value ?? table.Name;
}
protected string GetT_TableKeyColumnName() //Type type, DbContext context)
{
var table = GetT_Table_EntitySet(typeof(TEntity), db);
if (table.ElementType.KeyMembers.Count > 0)
return table.ElementType.KeyMembers[0].Name;
return "";
}
List<EntityTableColumn> GetT_TableColumnsList()
{
List<EntityTableColumn> columns = new List<EntityTableColumn>();
var table = GetT_Table_EntitySet(typeof(TEntity), db);
foreach (var p in table.ElementType.Properties)
columns.Add(new EntityTableColumn { Name = p.Name, ClrFullName = p.PrimitiveType.ClrEquivalentType.FullName });
return columns;
}
static EntitySet GetT_Table_EntitySet(Type type, DbContext context)
{
var metadata = ((IObjectContextAdapter)context).ObjectContext.MetadataWorkspace;
// Get the part of the model that contains info about the actual CLR types
var objectItemCollection = ((ObjectItemCollection)metadata.GetItemCollection(DataSpace.OSpace));
// Get the entity type from the model that maps to the CLR type
var entityType = metadata
.GetItems<EntityType>(DataSpace.OSpace)
.Single(e => objectItemCollection.GetClrType(e) == type);
// Get the entity set that uses this entity type
var entitySet = metadata
.GetItems<EntityContainer>(DataSpace.CSpace)
.Single()
.EntitySets
.Single(s => s.ElementType.Name == entityType.Name);
// Find the mapping between conceptual and storage model for this entity set
var mapping = metadata.GetItems<EntityContainerMapping>(DataSpace.CSSpace)
.Single()
.EntitySetMappings
.Single(s => s.EntitySet == entitySet);
// Find the storage entity set (table) that the entity is mapped
var table = mapping
.EntityTypeMappings.Single()
.Fragments.Single()
.StoreEntitySet;
return table;
// Return the table name from the storage entity set
//return (string)table.MetadataProperties["Table"].Value ?? table.Name;
}
// TODO - change to extension method
IQueryable<TEntity> OrderByFieldForPaging()
{
IQueryable<TEntity> q = dbSet;
string SortField = GetT_TableKeyColumnName();
bool Ascending = true;
var param = Expression.Parameter(typeof(TEntity), "p");
var prop = Expression.Property(param, SortField);
var exp = Expression.Lambda(prop, param);
string method = Ascending ? "OrderBy" : "OrderByDescending";
Type[] types = new Type[] { q.ElementType, exp.Body.Type };
var mce = Expression.Call(typeof(Queryable), method, types, q.Expression, exp);
return q.Provider.CreateQuery<TEntity>(mce);
}
IQueryable<TEntity> OrderByFieldForPaging(string propertyName, bool ascending)
{
IQueryable<TEntity> q = dbSet;
string SortField = (string.IsNullOrEmpty(propertyName)) ? GetT_TableKeyColumnName() : propertyName;
//bool Ascending = true;
var param = Expression.Parameter(typeof(TEntity), "p");
var prop = Expression.Property(param, SortField);
var exp = Expression.Lambda(prop, param);
string method = ascending ? "OrderBy" : "OrderByDescending";
Type[] types = new Type[] { q.ElementType, exp.Body.Type };
var mce = Expression.Call(typeof(Queryable), method, types, q.Expression, exp);
return q.Provider.CreateQuery<TEntity>(mce);
}
// TODO: copied from IM. BulkHelper extensions
Dictionary<int, List<int>> CreateChunksOfIds(List<int> ids, int chunkSize)
{
var result = new Dictionary<int, List<int>>();
var count = ids.Count();
var totalChunks = Math.Ceiling((double)count / (double)chunkSize);
var remainder = count % chunkSize;
//if not need to iterate
if (totalChunks < 2)
{
result.Add(0, ids.ToList());
return result;
}
var countFullChunks = totalChunks - 1;
var lastStartTake = 0;
for (int i = 0; i < countFullChunks; i++)
{
var startTake = (i * chunkSize); // 0, 100, 200
var endTake = ((i + 1) * chunkSize) - 1; // 99, 199, 299
var fullList = new List<int>();
for (int i2 = startTake; i2 <= endTake; i2++)
{
fullList.Add(ids[i2]);
}
result.Add(i, fullList);
lastStartTake = endTake + 1;
}
// Last chunk
var lastEndTake = lastStartTake + (remainder - 1);
var partialList = new List<int>();
for (int i2 = lastStartTake; i2 <= lastEndTake; i2++)
{
partialList.Add(ids[i2]);
}
result.Add((int)countFullChunks, partialList);
return result;
}
Dictionary<int, List<long>> CreateChunksOfIds(List<long> ids, int chunkSize)
{
var result = new Dictionary<int, List<long>>();
var count = ids.Count();
var totalChunks = Math.Ceiling((double)count / (double)chunkSize);
var remainder = count % chunkSize;
//if not need to iterate
if (totalChunks < 2)
{
result.Add(0, ids.ToList());
return result;
}
var countFullChunks = totalChunks - 1;
var lastStartTake = 0;
for (int i = 0; i < countFullChunks; i++)
{
var startTake = (i * chunkSize); // 0, 100, 200
var endTake = ((i + 1) * chunkSize) - 1; // 99, 199, 299
var fullList = new List<long>();
for (int i2 = startTake; i2 <= endTake; i2++)
{
fullList.Add(ids[i2]);
}
result.Add(i, fullList);
lastStartTake = endTake + 1;
}
// Last chunk
var lastEndTake = lastStartTake + (remainder - 1);
var partialList = new List<long>();
for (int i2 = lastStartTake; i2 <= lastEndTake; i2++)
{
partialList.Add(ids[i2]);
}
result.Add((int)countFullChunks, partialList);
return result;
}
#endregion
#region Utility Methods - Batch Operations
void util_AddEntityPropertyValuesSQL(TEntity entity, List<EntityTableColumn> columns, StringBuilder sb)
{
// reading entity property values
// http://msdn.microsoft.com/en-us/data/jj592677.aspx
if (columns == null || columns.Count <= 0)
return;
for (int i = 0; i < columns.Count; i++)
{
var col = columns[i];
// if numeric, string, or date etc. etc.
sb.Append("[" + col.Name + "]");
if (i < columns.Count - 1)
sb.Append(", ");
}
// db.Entry(entity).Property("")
}
void util_AddEntityColumnsSQL(List<EntityTableColumn> columns, StringBuilder sb)
{
if (columns == null && columns.Count <= 0)
return;
for (int i = 0; i < columns.Count; i++) //(var col in columns)
{
var col = columns[i];
sb.Append("[" + col.Name + "]");
if (i < columns.Count - 1)
sb.Append(", ");
}
}
#endregion
class EntityTableColumn
{
public string Name { get; set; }
public string ClrFullName { get; set; }
}
public ObjectContext GetObjectContext()
{
return ((IObjectContextAdapter)db).ObjectContext;
}
}
}