Click here to Skip to main content
15,888,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi everyone,

here i need to fetch data from table but i need to create repository dynamic instance and called method of repository ("FindBy") and passed lambada expression to that and getting out put from data but problem is how to fetch data from result view
that data is iqueryable please help me it urgent

C#
[HttpGet]
        public ActionResult Get(int iCustCode= 0)
        {

     Type classRepository = Type.GetType(String.Format("customer.Repository.{0}Repository,customer.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Customer"));

            Type classTypeModel = Type.GetType(String.Format("customer.DAL.Model.{0},customer.DAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Customer"));

                   
            var parametr = Expression.Parameter(classTypeModel, "x");
            var property = Expression.PropertyOrField(parametr, "CustCode");
            var body = Expression.Equal(property, Expression.Constant(iCustCode));
            var finalExpression = Expression.Lambda(body, parametr);


    // Create an instance of that type
            Object obj = Activator.CreateInstance(classRepository);
            // Retrieve the method you are looking for
            MethodInfo methodInfo = classRepository.GetMethod("FindBy");

     object[] parametersArray = new object[1];
            parametersArray[0] = finalExpression;
              // methodInfo.GetParameters().Where;

            // Invoke the method on the instance we created above
            var output = (IQueryable)methodInfo.Invoke(obj, parametersArray);




}



here i getting values in output in run time but how i get values

What I have tried:

C#
var Result = (from x in output.GetType() 
                          Select new viewmodel
            {
                CustName=x.  ???????            
        });
Posted
Updated 16-Jul-16 19:57pm
v2
Comments
Karthik_Mahalingam 17-Jul-16 1:58am    
.GetType() will retun the Type of the object, not the model

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900