public IEnumerable<TEntity> AllInclude<TEntity> (params System.Linq.Expressions.Expression<Func<TEntity, object>>[] includeProperties) where TEntity : class { return GetAllIncluding(includeProperties).ToList(); } public IQueryable<TEntity> GetAllIncluding<TEntity>(params Expression<Func<TEntity, object>>[] includeProperties) where TEntity : class { DbSet<TEntity> _dbSet = _submissionDbContext.Set<TEntity>(); IQueryable<TEntity> queryable = _dbSet.AsNoTracking(); return includeProperties.Aggregate(queryable, (current, includeProperty) => current.Include(includeProperty)); } public Tuple<IQueryable<TEntity>, int, int> ReviewedArticlesWithAuthor<TEntity>(string searchKey, string searchOption , int pageNumber, int pageSize) { var query = "EXEC spname@SearchKey, @SearchOption, @PageNumber, @PageSize"; var parameters = new[] { new SqlParameter("@SearchKey", searchKey) , new SqlParameter("@SearchOption", searchOption) , new SqlParameter("@PageNumber", pageNumber) , new SqlParameter("@PageSize", pageSize) }; IQueryable<TEntity> relatedArticleList; int totalPages; int totalRows; using (var multiResultSet = _submissionDbContext.MultiResultSetSqlQuery(query, parameters)) { relatedArticleList = multiResultSet.ResultSetFor<TEntity>().ToList().AsQueryable(); totalPages = multiResultSet.ResultSetFor<int>().ToArray().FirstOrDefault(); totalRows = multiResultSet.ResultSetFor<int>().ToArray().FirstOrDefault(); } return new Tuple<IQueryable<TEntity>, int, int>(relatedArticleList, totalPages, totalRows); }
modelBuilder.Entity<User>() .HasMany(u => u.Roles) .WithMany(r => r.Users) .Map(m => { m.ToTable("UserRoles"); m.MapLeftKey("UserId"); m.MapRightKey("RoleId"); });
public class Role { public int RoleId { get; set; } public string RoleName { get; set; } public virtual ICollection<User> Users { get; set; } }
public class User { public int UserId { get; set; } public string Username { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public string Password { get; set; } public bool IsActive { get; set; } public Guid ActivationCode { get; set; } public virtual ICollection<Role> Roles { get; set; } }