vendredi 11 septembre 2015

Get Method is null off IQueryable (Entity Framework)

I'm trying to pass lambda expressions and a type to my DAL. I have this statement:

(entities).GetType().GetMethod("Where")

"entities" is the Table of entities on the DataContext.

When I run the statement I get a null even though Linq.Table inherits IQueryable.

Anyone have an idea?

Here is the entire method:

public object GetResultSet(Dictionary<Type, Func<object, bool>> values)
        {
            using (ICSDataContext db = 
            DataContextFactory.CreateDataContext<ICSDataContext>(DataContexts.ICS))
            {
                foreach (var entry in values)
                {

                    var property = db.GetType().GetProperty(entry.Key.Name + "s");
                    IQueryable entities = (IQueryable)property.GetValue(db, null);                     

                    var whereMethod = (entities).GetType().GetMethod("Where")
                        .MakeGenericMethod(Type.GetType(entry.Key.AssemblyQualifiedName));


                    return whereMethod.Invoke(entities, new object[] { entry.Value });

                }
            }

            return null;
        }

Thanks





Aucun commentaire:

Enregistrer un commentaire