mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-10-31 07:49:26 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			26 lines
		
	
	
		
			786 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			786 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Text;
 | |
| 
 | |
| namespace FreeSql {
 | |
| 	internal class RepositoryDbContext<TEntity> : DbContext where TEntity : class {
 | |
| 
 | |
| 		protected BaseRepository<TEntity> _repos;
 | |
| 		public RepositoryDbContext(IFreeSql orm, BaseRepository<TEntity> repos) : base() {
 | |
| 			_orm = orm;
 | |
| 			_repos = repos;
 | |
| 			_isUseUnitOfWork = false;
 | |
| 		}
 | |
| 
 | |
| 		public override object Set(Type entityType) {
 | |
| 			if (_dicSet.ContainsKey(entityType)) return _dicSet[entityType];
 | |
| 			var sd = Activator.CreateInstance(typeof(RepositoryDbSet<>).MakeGenericType(entityType), _repos);
 | |
| 			_dicSet.Add(entityType, sd);
 | |
| 			return sd;
 | |
| 		}
 | |
| 
 | |
| 		RepositoryDbSet<TEntity> _dbSet;
 | |
| 		public RepositoryDbSet<TEntity> DbSet => _dbSet ?? (_dbSet = Set<TEntity>() as RepositoryDbSet<TEntity>);
 | |
| 	}
 | |
| }
 | 
