how can i write a generic query with EF and C#

c# entity-framework-6

Question

I want to construct an entity framework query that looks like this:

T entity = (from e in myContext.typeof(T) )

I tried using string concat to get a member from but it didn't work.myContext

further code

public T GetEntity<T>(Guid entityId, string connectionString)
{
    using (RContext rpContext = new RContext(connectionString))
    {

        var entity = (from e in rpContext.Set<T>()
                                    where e.Id == entityId
                                    select e).FirstOrDefault();
                    return (T) Convert.ChangeType(entity, typeof(T));

    }
}
1
0
6/8/2016 9:28:52 AM

Accepted Answer

ZZZ_tmp
0
6/8/2016 9:39:08 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow