Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. <#@ template debug="true" hostSpecific="true" #>
  2. <#@ output extension=".cs" #>
  3. <#@ Assembly Name="System.Core.dll" #>
  4. <#@ Assembly Name="System.Xml.dll" #>
  5. <#@ Assembly Name="System.Xml.Linq.dll" #>
  6. <#@ Assembly Name="System.Windows.Forms.dll" #>
  7. <#@ import namespace="System" #>
  8. <#@ import namespace="System.IO" #>
  9. <#@ import namespace="System.Diagnostics" #>
  10. <#@ import namespace="System.Linq" #>
  11. <#@ import namespace="System.Xml.Linq" #>
  12. <#@ import namespace="System.Collections" #>
  13. <#@ import namespace="System.Collections.Generic" #>
  14. <#
  15. /******************************************/
  16. // Add model entities in below array, template will automatically update the UnitOfWork template.
  17. var entities = new String[] {
  18. "Course",
  19. "Test"
  20. };
  21. /******************************************/
  22. #>
  23. /*****************************
  24. Generated by <#= Host.TemplateFile #>
  25.  
  26. Warning (AutoGenerated) - This file is autogenerated by UnitOfWork template file. DO NOT update code here to add a new entity.
  27. Add new entity in the UnitOfWorkFactory.tt code. Follow instructions in the source.
  28.  
  29. ******************************/
  30. using System;
  31. using System.Collections.Generic;
  32. using Domain_Repository.Domain;
  33. using Domain_Repository.Infrastructre;
  34. using System.Data.Entity;
  35. using Domain_Repository.Repository;
  36. using Domain_Repository.Repository.EF;
  37. namespace Domain_Repository.DataAccess
  38. {
  39. public static class UnitOfWorkFactory
  40. {
  41. private static IUnitOfWork _instance = null;
  42.  
  43. public static IUnitOfWork Create()
  44. {
  45. return _instance ?? new UnitOfWork();
  46. }
  47.  
  48. private partial class UnitOfWork : DbContext, IUnitOfWork
  49. {
  50. <# foreach(var entity in entities) {#>
  51. private DbSet<<#=entity #>> <#=entity #>s { get; set; }
  52. <#}#>
  53.  
  54. <# foreach(var entity in entities) {#>
  55. private Repository<<#=entity #>> _<#=entity.Replace(entity[0].ToString(), entity[0].ToString().ToLower()) #>Repository;
  56. <#}#>
  57.  
  58. internal UnitOfWork()
  59. {
  60. <# foreach(var entity in entities) {#>
  61. _<#=entity.Replace(entity[0].ToString(), entity[0].ToString().ToLower()) #>Repository = new Repository<<#=entity #>>(<#=entity #>s);
  62. <#}#>
  63. }
  64. <# foreach(var entity in entities) {#>
  65. public IRepository<<#=entity #>> <#=entity #>Repository
  66. {
  67. get { return _<#=entity.Replace(entity[0].ToString(), entity[0].ToString().ToLower()) #>Repository; }
  68. }
  69.  
  70. <#}#>
  71. public void Save()
  72. {
  73. SaveChanges();
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement