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
c # entity-framework entity-framework-6


source to share


No one has answered this question yet

Check out similar questions:

1758
How do I generate a random int?
783
Entity Framework vs LINQ to SQL
758
Entity Framework 5 Record Update
630
Fastest way to insert into Entity framework
515
How can I get the ID of the inserted entity in the Entity framework?
461
How do I view the SQL generated by the Entity Framework?
401
Entity Framework Service Provider not found for ADO.NET Provider with invariant name 'System.Data.SqlClient'
392
Failed to load Entity Framework provider type?
217
What LINQ Returns When Results Are Empty
3
Returning anonymous type using SqlQuery RAW query in Entity Framework



All Articles
Loading...
X
Show
Funny
Dev
Pics