Generic object for raw requests in Entity Framework

I am using EF and I need to do some custom queries that the user can create as needed.

I know for raw queries I should be using SqlQuery

, but I don't know of the object that the query returns.

I am using template UnitOfWork

:

public class Repository<TEntity> : IRepository<TEntity> where TEntity:class
{
    CellularFiveLocalEntities context = null;
    public Repository()
    {
        context = new CellularFiveLocalEntities();
    }

    private DbSet<TEntity> EntitySet
    {
        get { return context.Set<TEntity>(); }
    }

    public List<string> RawQuery(string query)
    {
        List<string> result = null;

        try {
            var entity = context.Set<string>();
            result = entity.SqlQuery(query).ToList();
        }
        catch (Exception ex) { 
            throw ex;
        }

        return result;
    }

    public void Dispose()
    {
        if (context != null)
        {
            context.Dispose();
        }
    }
}

      

How can I use a shared object for custom queries?

+3


source to share





All Articles