using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SqlSugar { public partial class SimpleClient : ISugarRepository, ISimpleClient where T : class, new() { #region Interface public virtual ISqlSugarClient Context { get; set; } public virtual ITenant AsTenant() { var result = this.Context as ITenant; if (result == null && this.Context is SqlSugarProvider) { result = (this.Context as SqlSugarProvider).Root as ITenant; } else if (result == null && this.Context is SqlSugarScopeProvider) { result = (this.Context as SqlSugarScopeProvider).conn.Root as ITenant; } return result; } public virtual ISqlSugarClient AsSugarClient() { return this.Context; } public SimpleClient() { } public SimpleClient(ISqlSugarClient context) { this.Context = context; } public SimpleClient Change() where ChangeType : class, new() { return this.Context.GetSimpleClient(); } public SimpleClient CopyNew() { SimpleClient sm = new SimpleClient(); sm.Context = this.Context.CopyNew(); return sm; } public virtual RepositoryType CopyNew() where RepositoryType : ISugarRepository { Type type = typeof(RepositoryType); var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any()); object o = null; if (isAnyParamter) { object[] pars = type.GetConstructors().First().GetParameters() .Select(it => (object)null).ToArray(); o = Activator.CreateInstance(type, pars); } else { o = Activator.CreateInstance(type); } var result = (RepositoryType)o; if (result.Context != null) { result.Context = result.Context.CopyNew(); } else { result.Context = this.Context.CopyNew(); } return result; } public virtual RepositoryType CopyNew(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository { var instance = handleDependencies(typeof(RepositoryType), serviceProvider, true); return (RepositoryType)instance; } private object handleDependencies(Type type, IServiceProvider serviceProvider, bool needNewCopy = false) { ConstructorInfo constructorInfo = null; var newInstanceType = type; if (type.IsInterface && IsAssignableToBaseRepository(type)) { var dependencyInstanceType = serviceProvider.GetService(type)?.GetType(); newInstanceType = dependencyInstanceType; constructorInfo = dependencyInstanceType.GetConstructors().FirstOrDefault(); } else { constructorInfo = type.GetConstructors().FirstOrDefault(); } var parameters = constructorInfo?.GetParameters(); if (parameters == null || parameters.Length == 0) { object dependencyInstance = serviceProvider.GetService(type); if (dependencyInstance is ISugarRepository sugarRepository) { return setContext(sugarRepository, needNewCopy); } else { return dependencyInstance; } } var conParas = new List(); foreach (var parameter in parameters) { Type dependencyType = parameter.ParameterType; conParas.Add(handleDependencies(dependencyType, serviceProvider)); } object instance = null; if (conParas != null && conParas.Count > 0) { instance = Activator.CreateInstance(newInstanceType, conParas.ToArray()); } else { instance = Activator.CreateInstance(newInstanceType); } return instance; } private ISugarRepository setContext(ISugarRepository sugarRepository, bool needNewCopy) { if (sugarRepository.Context != null) { if (needNewCopy) { sugarRepository.Context = sugarRepository.Context.CopyNew(); } } else { if (needNewCopy) { sugarRepository.Context = this.Context.CopyNew(); } else { sugarRepository.Context = this.Context; } } return sugarRepository; } private bool IsAssignableToBaseRepository(Type type) { var baseInterfaces = type.GetInterfaces(); foreach (Type interfaceType in baseInterfaces) { if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(ISimpleClient<>)) { Type genericArgument = interfaceType.GetGenericArguments()[0]; Type baseRepositoryGenericType = typeof(ISimpleClient<>).MakeGenericType(genericArgument); if (baseRepositoryGenericType.IsAssignableFrom(type)) { return true; } } } return false; } public virtual RepositoryType ChangeRepository() where RepositoryType : ISugarRepository { Type type = typeof(RepositoryType); var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any()); object o = null; if (isAnyParamter) { o = Activator.CreateInstance(type, new string[] { null }); } else { o = Activator.CreateInstance(type); } var result = (RepositoryType)o; if (result.Context == null) { result.Context = this.Context; } return result; } public virtual RepositoryType ChangeRepository(IServiceProvider serviceProvider) where RepositoryType : ISugarRepository { var instance = handleDependencies(typeof(RepositoryType), serviceProvider, false); return (RepositoryType)instance; } public virtual ISugarQueryable AsQueryable() { return Context.Queryable(); } public virtual IInsertable AsInsertable(T insertObj) { return Context.Insertable(insertObj); } public virtual IInsertable AsInsertable(T[] insertObjs) { return Context.Insertable(insertObjs); } public virtual IInsertable AsInsertable(List insertObjs) { return Context.Insertable(insertObjs); } public virtual IUpdateable AsUpdateable(T updateObj) { return Context.Updateable(updateObj); } public virtual IUpdateable AsUpdateable(T[] updateObjs) { return Context.Updateable(updateObjs); } public virtual IUpdateable AsUpdateable(List updateObjs) { return Context.Updateable(updateObjs); } public virtual IUpdateable AsUpdateable() { return Context.Updateable(); } public virtual IDeleteable AsDeleteable() { return Context.Deleteable(); } #endregion #region Method public virtual T GetById(dynamic id) { return Context.Queryable().InSingle(id); } public virtual List GetList() { return Context.Queryable().ToList(); } public virtual List GetList(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).ToList(); } public virtual T GetSingle(Expression> whereExpression) { return Context.Queryable().Single(whereExpression); } public virtual T GetFirst(Expression> whereExpression) { return Context.Queryable().First(whereExpression); } public virtual List GetPageList(Expression> whereExpression, PageModel page) { int count = 0; var result = Context.Queryable().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.TotalCount = count; return result; } public virtual List GetPageList(Expression> whereExpression, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { int count = 0; var result = Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count); page.TotalCount = count; return result; } public virtual List GetPageList(List conditionalList, PageModel page) { int count = 0; var result = Context.Queryable().Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count); page.TotalCount = count; return result; } public virtual List GetPageList(List conditionalList, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { int count = 0; var result = Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageList(page.PageIndex, page.PageSize, ref count); page.TotalCount = count; return result; } public virtual bool IsAny(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).Any(); } public virtual int Count(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).Count(); } public virtual bool Insert(T insertObj) { return this.Context.Insertable(insertObj).ExecuteCommand() > 0; } public virtual bool InsertOrUpdate(T data) { return this.Context.Storageable(data).ExecuteCommand() > 0; } public virtual bool InsertOrUpdate(List datas) { return this.Context.Storageable(datas).ExecuteCommand() > 0; } public virtual int InsertReturnIdentity(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnIdentity(); } public virtual long InsertReturnBigIdentity(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnBigIdentity(); } public virtual long InsertReturnSnowflakeId(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnSnowflakeId(); } public virtual List InsertReturnSnowflakeId(List insertObjs) { return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdList(); } public virtual Task InsertReturnSnowflakeIdAsync(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnSnowflakeIdAsync(); } public virtual Task> InsertReturnSnowflakeIdAsync(List insertObjs) { return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync(); } public virtual T InsertReturnEntity(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnEntity(); } public virtual bool InsertRange(T[] insertObjs) { return this.Context.Insertable(insertObjs).ExecuteCommand() > 0; } public virtual bool InsertRange(List insertObjs) { return this.Context.Insertable(insertObjs).ExecuteCommand() > 0; } public virtual bool Update(T updateObj) { return this.Context.Updateable(updateObj).ExecuteCommand() > 0; } public virtual bool UpdateRange(T[] updateObjs) { return this.Context.Updateable(updateObjs).ExecuteCommand() > 0; } public virtual bool UpdateRange(List updateObjs) { return this.Context.Updateable(updateObjs).ExecuteCommand() > 0; } public virtual bool Update(Expression> columns, Expression> whereExpression) { return this.Context.Updateable().SetColumns(columns).Where(whereExpression).ExecuteCommand() > 0; } public virtual bool UpdateSetColumnsTrue(Expression> columns, Expression> whereExpression) { return this.Context.Updateable().SetColumns(columns, true).Where(whereExpression).ExecuteCommand() > 0; } public virtual bool Delete(T deleteObj) { return this.Context.Deleteable().Where(deleteObj).ExecuteCommand() > 0; } public virtual bool Delete(List deleteObjs) { return this.Context.Deleteable().Where(deleteObjs).ExecuteCommand() > 0; } public virtual bool Delete(Expression> whereExpression) { return this.Context.Deleteable().Where(whereExpression).ExecuteCommand() > 0; } public virtual bool DeleteById(dynamic id) { return this.Context.Deleteable().In(id).ExecuteCommand() > 0; } public virtual bool DeleteByIds(dynamic[] ids) { return this.Context.Deleteable().In(ids).ExecuteCommand() > 0; } #endregion #region Async Method public virtual Task GetByIdAsync(dynamic id) { return Context.Queryable().InSingleAsync(id); } public virtual Task> GetListAsync() { return Context.Queryable().ToListAsync(); } public virtual Task> GetListAsync(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).ToListAsync(); } public virtual Task GetSingleAsync(Expression> whereExpression) { return Context.Queryable().SingleAsync(whereExpression); } public virtual Task GetFirstAsync(Expression> whereExpression) { return Context.Queryable().FirstAsync(whereExpression); } public virtual async Task> GetPageListAsync(Expression> whereExpression, PageModel page) { RefAsync count = 0; var result = await Context.Queryable().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual async Task> GetPageListAsync(Expression> whereExpression, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { RefAsync count = 0; var result = await Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual async Task> GetPageListAsync(List conditionalList, PageModel page) { RefAsync count = 0; var result = await Context.Queryable().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual async Task> GetPageListAsync(List conditionalList, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { RefAsync count = 0; var result = await Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual Task IsAnyAsync(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).AnyAsync(); } public virtual Task CountAsync(Expression> whereExpression) { return Context.Queryable().Where(whereExpression).CountAsync(); } public virtual async Task InsertOrUpdateAsync(T data) { return await this.Context.Storageable(data).ExecuteCommandAsync() > 0; } public virtual async Task InsertOrUpdateAsync(List datas) { return await this.Context.Storageable(datas).ExecuteCommandAsync() > 0; } public virtual async Task InsertAsync(T insertObj) { return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0; } public virtual Task InsertReturnIdentityAsync(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnIdentityAsync(); } public virtual Task InsertReturnBigIdentityAsync(T insertObj) { return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync(); } public virtual async Task InsertReturnEntityAsync(T insertObj) { return await this.Context.Insertable(insertObj).ExecuteReturnEntityAsync(); } public virtual async Task InsertRangeAsync(T[] insertObjs) { return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; } public virtual async Task InsertRangeAsync(List insertObjs) { return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; } public virtual async Task UpdateAsync(T updateObj) { return await this.Context.Updateable(updateObj).ExecuteCommandAsync() > 0; } public virtual async Task UpdateRangeAsync(T[] updateObjs) { return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0; } public virtual async Task UpdateRangeAsync(List updateObjs) { return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0; } public virtual async Task UpdateAsync(Expression> columns, Expression> whereExpression) { return await this.Context.Updateable().SetColumns(columns).Where(whereExpression).ExecuteCommandAsync() > 0; } public virtual async Task UpdateSetColumnsTrueAsync(Expression> columns, Expression> whereExpression) { return await this.Context.Updateable().SetColumns(columns, true).Where(whereExpression).ExecuteCommandAsync() > 0; } public virtual async Task DeleteAsync(T deleteObj) { return await this.Context.Deleteable().Where(deleteObj).ExecuteCommandAsync() > 0; } public virtual async Task DeleteAsync(List deleteObjs) { return await this.Context.Deleteable().Where(deleteObjs).ExecuteCommandAsync() > 0; } public virtual async Task DeleteAsync(Expression> whereExpression) { return await this.Context.Deleteable().Where(whereExpression).ExecuteCommandAsync() > 0; } public virtual async Task DeleteByIdAsync(dynamic id) { return await this.Context.Deleteable().In(id).ExecuteCommandAsync() > 0; } public virtual async Task DeleteByIdsAsync(dynamic[] ids) { return await this.Context.Deleteable().In(ids).ExecuteCommandAsync() > 0; } #endregion #region Async Method CancellationToken public virtual Task InsertReturnSnowflakeIdAsync(T insertObj, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return this.Context.Insertable(insertObj).ExecuteReturnSnowflakeIdAsync(); } public virtual Task> InsertReturnSnowflakeIdAsync(List insertObjs, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return this.Context.Insertable(insertObjs).ExecuteReturnSnowflakeIdListAsync(); } public virtual Task GetByIdAsync(dynamic id, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return Context.Queryable().InSingleAsync(id); } public virtual Task> GetListAsync(CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return Context.Queryable().ToListAsync(); } public virtual Task> GetListAsync(Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return Context.Queryable().Where(whereExpression).ToListAsync(); } public virtual Task GetSingleAsync(Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return Context.Queryable().SingleAsync(whereExpression); } public virtual Task GetFirstAsync(Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return Context.Queryable().FirstAsync(whereExpression); } public virtual async Task> GetPageListAsync(Expression> whereExpression, PageModel page, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; RefAsync count = 0; var result = await Context.Queryable().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual async Task> GetPageListAsync(Expression> whereExpression, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken = default) { this.Context.Ado.CancellationToken = cancellationToken; RefAsync count = 0; var result = await Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual async Task> GetPageListAsync(List conditionalList, PageModel page, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; RefAsync count = 0; var result = await Context.Queryable().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual async Task> GetPageListAsync(List conditionalList, PageModel page, Expression> orderByExpression = null, OrderByType orderByType = OrderByType.Asc, CancellationToken cancellationToken = default) { this.Context.Ado.CancellationToken = cancellationToken; RefAsync count = 0; var result = await Context.Queryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count); page.TotalCount = count; return result; } public virtual Task IsAnyAsync(Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return Context.Queryable().Where(whereExpression).AnyAsync(); } public virtual Task CountAsync(Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return Context.Queryable().Where(whereExpression).CountAsync(); } public virtual async Task InsertOrUpdateAsync(T data, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Storageable(data).ExecuteCommandAsync() > 0; } public virtual async Task InsertOrUpdateAsync(List datas, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Storageable(datas).ExecuteCommandAsync() > 0; } public virtual async Task InsertAsync(T insertObj, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0; } public virtual Task InsertReturnIdentityAsync(T insertObj, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return this.Context.Insertable(insertObj).ExecuteReturnIdentityAsync(); } public virtual Task InsertReturnBigIdentityAsync(T insertObj, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync(); } public virtual async Task InsertReturnEntityAsync(T insertObj, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Insertable(insertObj).ExecuteReturnEntityAsync(); } public virtual async Task InsertRangeAsync(T[] insertObjs, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; } public virtual async Task InsertRangeAsync(List insertObjs, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; } public virtual async Task UpdateAsync(T updateObj, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Updateable(updateObj).ExecuteCommandAsync() > 0; } public virtual async Task UpdateRangeAsync(T[] updateObjs, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0; } public virtual async Task UpdateRangeAsync(List updateObjs, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Updateable(updateObjs).ExecuteCommandAsync() > 0; } public virtual async Task UpdateAsync(Expression> columns, Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Updateable().SetColumns(columns).Where(whereExpression).ExecuteCommandAsync() > 0; } public virtual async Task UpdateSetColumnsTrueAsync(Expression> columns, Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Updateable().SetColumns(columns, true).Where(whereExpression).ExecuteCommandAsync() > 0; } public virtual async Task DeleteAsync(T deleteObj, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Deleteable().Where(deleteObj).ExecuteCommandAsync() > 0; } public virtual async Task DeleteAsync(List deleteObjs, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Deleteable().Where(deleteObjs).ExecuteCommandAsync() > 0; } public virtual async Task DeleteAsync(Expression> whereExpression, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Deleteable().Where(whereExpression).ExecuteCommandAsync() > 0; } public virtual async Task DeleteByIdAsync(dynamic id, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Deleteable().In(id).ExecuteCommandAsync() > 0; } public virtual async Task DeleteByIdsAsync(dynamic[] ids, CancellationToken cancellationToken) { this.Context.Ado.CancellationToken = cancellationToken; return await this.Context.Deleteable().In(ids).ExecuteCommandAsync() > 0; } public int Count(List conditionalModels) { return Context.Queryable().Where(conditionalModels).Count(); } public bool Delete(List conditionalModels) { return Context.Deleteable().Where(conditionalModels).ExecuteCommandHasChange(); } public List GetList(Expression> whereExpression, List orderByModels) { return Context.Queryable().Where(whereExpression).OrderBy(orderByModels).ToList(); } public List GetList(List conditionalList) { return Context.Queryable().Where(conditionalList).ToList(); } public List GetList(List conditionalList, List orderByModels) { return Context.Queryable().Where(conditionalList).OrderBy(orderByModels).ToList(); } public List GetPageList(Expression> whereExpression, PageModel page, List orderByModels) { var total = 0; var list = Context.Queryable().Where(whereExpression).OrderBy(orderByModels).ToPageList(page.PageIndex, page.PageSize, ref total); page.TotalCount = total; return list; } public List GetPageList(List conditionalList, PageModel page, List orderByModels) { var total = 0; var list = Context.Queryable().Where(conditionalList).OrderBy(orderByModels).ToPageList(page.PageIndex, page.PageSize, ref total); page.TotalCount = total; return list; } public T GetSingle(List conditionalModels) { return Context.Queryable().Where(conditionalModels).Single(); } public T GetFirst(List conditionalModels) { return Context.Queryable().Where(conditionalModels).First(); } public bool IsAny(List conditionalModels) { return Context.Queryable().Where(conditionalModels).Any(); } public T GetFirst(Expression> whereExpression, List orderByModels) { return Context.Queryable().Where(whereExpression).OrderBy(orderByModels).First(); } public T GetFirst(List conditionalModels, List orderByModels) { return Context.Queryable().Where(conditionalModels).OrderBy(orderByModels).First(); } #endregion } }