Base solution for your next web application

Activities of "radek stromský"

It would be enough to add support for projection for FirstOrDefaultAsync and GetAllListAsync. That should cover most of the scenarios. Overload would cause a problems, so designed the interface methods like this:

Task<TModel> QueryFirstOrDefaultAsync<TModel>(Func<IQueryable<TEntity>, IQueryable<TModel>> projection);
Task<List<TModel>> QueryToListAsync<TModel>(Func<IQueryable<TEntity>, IQueryable<TModel>> projection);

Usage example:

var result = await _myRepo.QueryFirstOrDefaultAsync(q =>  q.Where(x => x.Id == id).ProjectTo<MyDto>());

or without using AutoMapper's IQuerable extension:

var result = await _myRepo.QueryFirstOrDefaultAsync(q =>  q.Where(x => x.Id == id).Select(x => x.Status));

Such implementation for EF repository is quite straightforward. Not sure about NHibernate.

What is your opinion on this?

PS: I can contribute if we agree on this solution. I am also opened to any suggestions how should final method names look like.

Problem solved!

My base controller class wan't abstract. When I changed it to abstract, log record for controller's proxy is no longer saved to database.

Hi,

when I am logging MvcController's actions it gets logged twice. One record for real controller and second for proxy created by castle dynamic proxy.

Single request for Home/Index results in two records in Audit log

  1. MyWebSite.Controllers.HomeController
  2. Castle.Proxies.HomeControllerProxy

Is there a way remove proxies from logging? I am unable to change this behaviour by using Auditing Selectors.

Any suggestions? Thanks

Hi,

It looks like Microsoft.Bcl.Immutable package has been removed from nuget gallery. Do you have a plan to use System.Collections.Immutable package instead?

Radek

I don't know when OData is done with IQueryable either. Only working solution I can think of is disposing DbContext inside Dispose(bool) method of the controller. That is what I am doing now. But I don't like an idea of using DbContext inside WebApi project instead of repositories.

Unfortunately this doesn't fix the problem. DbContext is still disposed before ODataController is able to apply query options to IQueryable object.

InvalidOperationException: The operation cannot be completed because the DbContext has been disposed.

Hi,

I want to implement support for querying data using OData protocol v4. I have working example with fake data. Now I am trying to read data from database, but I don't see how I could possibly use combination of repository's IQueryable<T> GetAll() and UnitOfWork attribute.

I would like to have ODataController to look like this :

public class UsersController : ODataController
	{
		private readonly IUserRepository _userRepo;

		public UsersController(IUserRepository userRepo)
		{
			_userRepo = userRepo;
		}

		[EnableQuery]
		[UnitOfWork] // this will not work
		public IQueryable<User> Get()
		{
			return _userRepo.GetAll(); // this is the problem - DbContext will be disposed before it is needed.
		}
	}

I was able to get things done by using folowing alternative code:

[EnableQuery]
		public IEnumerable<User> Get(ODataQueryOptions<User> query)
		{
			return _userRepo.Query( q => query.ApplyTo(q).Cast<User>().ToList());
		}

But former solution is much better and cleaner only if it would work. Is there any possibility to keep DbContext alive to the point when Controller itself is disposed? E.g. something like UnitOfWork placed on entire controller not only its action?

Thanks of any suggestions.

Showing 1 to 7 of 7 entries