I have a User
that is assigned to a Client
. When pulling out the User
object, I get the Client
object as part of it. Simple.
This works as it should when logging in. The User
object has a Client
, no matter who I log in as.
However, using the exact same method to get the User
as when logging in, to edit it via the admin menus, the Client
is sometimes null
.
I say sometimes:
1) In Firefox - When attempting to view the details of most, but not all, users (and myself), the Client
attached to the User
will be null
. Only a couple of the Users
will be viewable due to the Client
actually existing.
2) In Chrome - All users (EXCEPT myself) are visible. Only when attempting to view my own user will the Client
be null
.
I don't understand; Both browsers are simply going to the same URLs, i.e. /Users/EditGet/28
and even using two different methods (GetById
and GetByUserName
) it provides the same results - though admittedly both make use of the base Get function:
Edit: The BaseService class together rather over edits.
internal CustomContext context;
internal DbSet<TEntity> dbSet;
public BaseService(CustomContext context)
{
this.context = context;
this.dbSet = context.Set<TEntity>();
}
public virtual IEnumerable<TEntity> Get(
Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
string includeProperties = "")
{
IQueryable<TEntity> query = dbSet.Where(e => !e.Deleted);
if (filter != null)
{
query = query.Where(filter);
}
foreach (var includeProperty in includeProperties.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeProperty);
}
return orderBy != null ? orderBy(query).ToList() : query.ToList();
}
I'm not sure why the choice of browser should affect the results of a back-end query at all. Surely it should return the Client
with the User
regardless of what browser I use.
I assume perhaps a basic fault with the base Get method, but it doesn't explain the behaviour that I'm seeing...
If anyone could shed any light on this, I would be most appreciative.
Edit 2: CustomContext:
public class CustomContext : DbContext, ICustomContext
{
public IDbSet<User> Users { get; set; }
public IDbSet<Client> Clients { get; set; }
}