Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#@ template debug="true" hostSpecific="true" #>
- <#@ output extension=".cs" #>
- <#@ Assembly Name="System.Core.dll" #>
- <#@ Assembly Name="System.Xml.dll" #>
- <#@ Assembly Name="System.Xml.Linq.dll" #>
- <#@ Assembly Name="System.Windows.Forms.dll" #>
- <#@ import namespace="System" #>
- <#@ import namespace="System.IO" #>
- <#@ import namespace="System.Diagnostics" #>
- <#@ import namespace="System.Linq" #>
- <#@ import namespace="System.Xml.Linq" #>
- <#@ import namespace="System.Collections" #>
- <#@ import namespace="System.Collections.Generic" #>
- <#
- /******************************************/
- // Add model entities in below array, template will automatically update the UnitOfWork template.
- var entities = new String[] {
- "Course",
- "Test"
- };
- /******************************************/
- #>
- /*****************************
- Generated by <#= Host.TemplateFile #>
- Warning (AutoGenerated) - This file is autogenerated by UnitOfWork template file. DO NOT update code here to add a new entity.
- Add new entity in the UnitOfWorkFactory.tt code. Follow instructions in the source.
- ******************************/
- using System;
- using System.Collections.Generic;
- using Domain_Repository.Domain;
- using Domain_Repository.Infrastructre;
- using System.Data.Entity;
- using Domain_Repository.Repository;
- using Domain_Repository.Repository.EF;
- namespace Domain_Repository.DataAccess
- {
- public static class UnitOfWorkFactory
- {
- private static IUnitOfWork _instance = null;
- public static IUnitOfWork Create()
- {
- return _instance ?? new UnitOfWork();
- }
- private partial class UnitOfWork : DbContext, IUnitOfWork
- {
- <# foreach(var entity in entities) {#>
- private DbSet<<#=entity #>> <#=entity #>s { get; set; }
- <#}#>
- <# foreach(var entity in entities) {#>
- private Repository<<#=entity #>> _<#=entity.Replace(entity[0].ToString(), entity[0].ToString().ToLower()) #>Repository;
- <#}#>
- internal UnitOfWork()
- {
- <# foreach(var entity in entities) {#>
- _<#=entity.Replace(entity[0].ToString(), entity[0].ToString().ToLower()) #>Repository = new Repository<<#=entity #>>(<#=entity #>s);
- <#}#>
- }
- <# foreach(var entity in entities) {#>
- public IRepository<<#=entity #>> <#=entity #>Repository
- {
- get { return _<#=entity.Replace(entity[0].ToString(), entity[0].ToString().ToLower()) #>Repository; }
- }
- <#}#>
- public void Save()
- {
- SaveChanges();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement