Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to pass it to another method?
Message
 
 
To
11/01/2013 16:09:41
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01562213
Message ID:
01562281
Views:
32
>>>>Hi everybody,
>>>>
>>>>In the top of my code in one method I have this declaration
>>>>
>>>>
>>>>var clients = Db.Clients;
>>>>
>>>>I need to pass this object to another method. The method in the prototype application I am looking for has this signature:
>>>>
>>>>private JsonResult CreateFlexiJson(IEnumerable<JobPost> items, int page, int total)
>>>>
>>>>How can I introduce the same method for my case to be able to pass that clients variable to it?
>>>>
>>>>Thanks in advance.
>>>
>>>
>>>private JsonResult CreateFlexiJson(IEnumerable<JobPost> items, int page, int total, ??? clients = null)
>>
>>No, I need the clients to become IEnumerable in the declaration. E.g. in the sample application I am working with
>>http://www.s4sme.com/Blog/Post/aspnet-mvc-4-application-with-flexigrid-jquery-ui-and-jquery-validation
>>
>>he is using Jobs (and he uses XML for repository, I guess for simplicity), but in my case my class is Client, but I only have repository available and I access clients by querying Db.Clients. And I need to figure out how to replace the first parameter in that declaration for my case.
>>
>>The only solution I was able to implement is
>>
>>
>>private JsonResult CreateFlexiJson(IEnumerable<Client> items, int page, int total)
>>        {
>>            return Json(
>>                    new
>>                    {
>>                        page,
>>                        total,
>>                        rows =
>>                            items
>>                            .Select(x =>
>>                                new
>>                                {
>>                                    id = x.Id,
>>                                    // either use GetPropertyList(x) method to get all columns 
>>                                    cell = new { Id = x.Id, Number = x.Number, Name = x.Name, Contact1 = x.Contact1.Contact ?? String.Empty }
>>                                })
>>                    }, JsonRequestBehavior.AllowGet);
>>        }
>>
>>E.g. I had to bring Objects reference to that project. Don't know if there are any problems with this approach.
>
>Create a class to hold the dbClients properties....Use linq to select from dbClients into an a new instance of you class type then use .ToList() which creates the IEnumerable of your new type. pass that to the function. You really need to learn to think outside of what someone else is doing to solve your problems..

Excellent post, John.
Previous
Reply
Map
View

Click here to load this message in the networking platform