Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "mhrabak"

Sorry for delayed answer. I'm overhelmed by porting our current solution to aspnet zero. We solve it that way we inherit our ViewModels from Entity<TPrimaryKey> for these ViewModels we create DbQuery in DbContext (otherwise exception is thrown from Abp) and our repositories works with ViewModels and inside concrete implementation of Repository we map Entity to ViewModel - for now using AppServices without OData - this will come later we now need to quickly port base functionality. Idea behind Odata is to create OData controller and using DI we will inject concrete AppService to this controller thanks to this we will have all previously created functionality with support for OData - just idea not tested if possible.

Thanks I thought it will be something like that what cause the problem. Is there some way how to obtain this functionality and be able to use Repository without IEntity and keep your functionality behind the scenes? We don't know much about your structures yet but I presume Repository has some hidden functionality which we can loose when we start to create and register our own custom repositories and do not use yours IRepository or am I mistaken?

We are thinking about something like this:

 public class TaskRepository : CustomRepo<TaskDto> {
        public TaskRepository(IDbContextProvider<AttisDemoDbContext> dbContextProvider) : base(dbContextProvider) {
        }
    }

  public abstract class CustomRepo<TDto, TPrimaryKey>
        where TDto : IDto<TPrimaryKey> {
        protected readonly AttisDemoDbContext Ctx;
        protected CustomRepo(IDbContextProvider<AttisDemoDbContext> dbContextProvider) {
            Ctx = dbContextProvider.GetDbContext();
        }

        public virtual Task<IQueryable<TDto>> GetAllAsync() {
            return Task.FromResult(GetAll());
        }

        public abstract IQueryable<TDto> GetAll();
        .
        .
        .
        etc.
    }

    public interface IDto<TPrimaryKey> : IDto {
        TPrimaryKey Id { get; set; }
    }

    public interface IDto {
        object KeyValue { get; }
    }

Structure is similar to yours but with that change TaskDto is not an entity registered to DbContext - now I expect to override GetAll method get desired DbSet join another DBSets if desired, filter record/s I want and return them in structure of my choice. So I think the only problem is part of code you posted as answer the rest is OK I think. What I dont know is where to get MultitenancySIte for GetDbContext method. I guess this parameter is necessary if we want to support multitenancy and keep DbContext works correctly with tenancy.

Hope you understand why we need this.

@ismcagdas Yes, We have implemented such functionality (code from my initial post). Question is if exists such possibility with asp.net zero. Reasons to do it is same as for common controller - security, not to show all properties from entity and that ViewModel can be different from Entity of course which is our reason why we need such functionality.

Yes I sucessfully implemented approach 2, but question was quite different. I asked how can we use OData in ASP.NET Zero with DTOs/ViewModels instead of Entities.

P.S.: Can you please update your documentation for ASP.NET Core v2.2 it is necessary to registee MvcCore pipe like this: https://github.com/OData/WebApi/issues/1707

services.AddMvcCore(options => { options.EnableEndpointRouting = false; foreach (var outputFormatter in options.OutputFormatters.OfType<ODataOutputFormatter>().Where(_ => _.SupportedMediaTypes.Count == 0)) { outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata")); } foreach (var inputFormatter in options.InputFormatters.OfType<ODataInputFormatter>().Where(_ => _.SupportedMediaTypes.Count == 0)) { inputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata")); } }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

Showing 11 to 14 of 14 entries