MagicTester MagicTester - 1 year ago 140
C# Question

SingleResult Web Api remove Queryable

I've been trying to access my object

by using

The issue here is that my API is returning a wrapped object containing [1] element.

Answer Source

The problem is that your SingleResult.Create() is creating a wrapper object for your entity, where what you SEEM to want is the entity itself. Either use another method internal to your project that doesn't wrap your object (no idea what that would be), or change the signature of your method and return the entity directly.

public virtual TEntity GetById(int id)
        var data = GetDataById(id);
        return data; 
    catch (Exception e)
        throw e;

public virtual TEntity GetbyId(int id)
    var data = _ctx.Set<TEntity>().Where(e => e.Id == id);
    var entity = data.FirstOrDefault();
    return entity;