Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to declare the variable correctly?
Message
De
28/09/2012 14:54:33
 
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01553872
Message ID:
01553877
Vues:
57
>Hi everybody,
>
>I am trying to write a Search method that can accept two parameters (no or Name). Here is what I've started, but I don't know how should I declare "clients" variable at the top correctly. What is it when used in LINQ query?
>
>
>public ActionResult Search(int? clientNo = null, string clientName = null)
>        {
>            
>            if (((clientNo??0) == 0) && (String.IsNullOrEmpty(clientName)==true))
>            {
>                // Assume we want to select everything
>                var clients = Db.Clients.OrderBy(c => c.Name);
>            }
>            var clients = Db.Clients.Where(c => (c.Number == clientNo)).OrderBy(c => c.Name);
>
>            return PartialView("_ClientsSearch", clients);
>        }
>
>Since I can not declare var clients twice, what will be correct solution here?
>
>Thanks in advance.
public ActionResult Search(int? clientNo = null, string clientName = null)
        {
            var clients;
            if (((clientNo??0) == 0) && (String.IsNullOrEmpty(clientName)==true))
            {
                // Assume we want to select everything
                clients = Db.Clients.OrderBy(c => c.Name);
            }
            clients = Db.Clients.Where(c => (c.Number == clientNo)).OrderBy(c => c.Name);

            return PartialView("_ClientsSearch", clients);
        }
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform