Bonjour,
J'ai un objet ThirdParty :
et la méthode suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 public class ThirdParty { [Required(ErrorMessage = "OID is required.")] public int OID { get; set; } [Required(ErrorMessage = "Name is required.")] [StringLength(255, ErrorMessage = "Name must be under 255 characters.")] public string Name { get; set; } }
J'ai besoin en fait de retourner en dur un ThirdParty en plus qui aurait un OID à -1 et un Name à "toto" quand on appelle GetThirdPartys(9999).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public static IList<ThirdParty> GetThirdPartys(int OID) { IList<ThirdParty> tps = null; if (OID != 9999) { tps = (from tp in DB.ThirdParties where tp.OID == OID orderby tp.Name select new ThirdParty { OID = tp.OID, Name = tp.Name }).ToList(); } else { tps = (from tp in DB.ThirdParties orderby tp.Name select new ThirdParty { OID = tp.OID, Name = tp.Name, }).ToList(); } return tps; }
Je voulais faire du genre comme ça, mais ça ne fonctionne pas, problème de syntaxe ? :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public static IList<ThirdParty> GetThirdPartys(int OID) { IList<ThirdParty> tps = null; if (OID != 9999) { tps = (from tp in DB.ThirdParties where tp.OID == OID orderby tp.Name select new ThirdParty { OID = tp.OID, Name = tp.Name }).ToList(); } else { tps = (from tp in DB.ThirdParties orderby tp.Name select new ThirdParty { OID = tp.OID, Name = tp.Name, }).Union(select new ThirdParty { OID = -1, Name = "toto", }).ToList(); } return tps; }
Partager