|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jan 2005
Città: A casa mia
Messaggi: 825
|
[c#] Problema linq selezione Attributi che possono essere null
Ho questo linq
Codice:
var IndirizziClienti = (from C in mioDatabase.Clienti
join IC in mioDatabase.IndirizziClienti on C.ID equals IC.IDClienti
join I in mioDatabase.Indirizzi on IC.IDIndirizzi equals I.ID
select new { C.Nome, I.Indirizzo, I.Civico, I.Citta, I.CAP, C.Telefono, C.Referente}).ToList();
Telefono è string Voglio nel select se TELEFONO è null, mi venga restituito una stringa vuota "". Come fare? |
|
|
|
|
|
#2 |
|
Member
Iscritto dal: Dec 2005
Città: Provincia di Vicenza
Messaggi: 174
|
ciao,
non l'ho provato e non so se funziona su una query LINQ ma puoi provare cosi: Codice:
var IndirizziClienti = (from C in mioDatabase.Clienti
join IC in mioDatabase.IndirizziClienti on C.ID equals IC.IDClienti
join I in mioDatabase.Indirizzi on IC.IDIndirizzi equals I.ID
select new { C.Nome, I.Indirizzo, I.Civico, I.Citta, I.CAP, C.Telefono == null ? String.Empty : C.Telefono, C.Referente}).ToList();
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: May 2004
Città: Londra (Torino)
Messaggi: 3692
|
Giusto.
e per essere piu' raffinati, consiglio l'operatore ?? (questo sconosciuto) C.Telefono == null ? String.Empty : C.Telefono equivale a C.Telefono ?? string.Empty ovvero restituisce il termine sinistro. Ma se il sinistro e' null, allora restituisce il destro.
__________________
Se pensi che il tuo codice sia troppo complesso da capire senza commenti, e' segno che molto probabilmente il tuo codice e' semplicemente mal scritto. E se pensi di avere bisogno di un nuovo commento, significa che ti manca almeno un test. |
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Quante volte mi è capitato di desiderare un operatore del genere
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Feb 2003
Città: Stockholm (SE)
Messaggi: 1343
|
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Beh, Java non è solo Java (come .NET non è solo C#) e quando uso Scala ho le Option, che sono ancora più eleganti e potenti... statte buono
E' che ho usato un sacco l'operatore ternario (brutto, brutto, brutto
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: Feb 2003
Città: Stockholm (SE)
Messaggi: 1343
|
Quote:
e per rendere questo post un po' piú utile... http://msdn.microsoft.com/en-us/library/ms173224.aspx |
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Chiaro, ma come potevo non risponderti?
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
|
|
|
|
#9 | |
|
Senior Member
Iscritto dal: Jul 2005
Città: Bologna
Messaggi: 1130
|
Quote:
ps. che ti ha fatto di male l'operatore ternario?
__________________
-> The Motherfucking Manifesto For Programming, Motherfuckers |
|
|
|
|
|
|
#10 | |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Il mio analista? ![]() edit: l'operatore ternario non mi ha fatto niente (a me piace), solo che ha una cattiva reputazione (non ricordo dove ho letto tutti i "misusing" a cui si presta)
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) Ultima modifica di banryu79 : 20-06-2011 alle 12:13. |
|
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Feb 2003
Città: Stockholm (SE)
Messaggi: 1343
|
|
|
|
|
|
|
#12 |
|
Senior Member
Iscritto dal: Jul 2005
Città: Bologna
Messaggi: 1130
|
Beh, se continui ad usare java di tua spontanea volontà nel 2011, probabilmente è dovuto a qualche conflitto infantile irrisolto
__________________
-> The Motherfucking Manifesto For Programming, Motherfuckers |
|
|
|
|
|
#13 |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Mi salvo un pochino se ti dico che sto imparando ad aprezzare anche Scala (anche se sono agli inizi)?
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
|
|
|
|
#14 |
|
Member
Iscritto dal: May 2009
Messaggi: 274
|
ma usi le join nelle tue query perché si tratta di LINQ2SQL?
|
|
|
|
|
|
#15 |
|
Senior Member
Iscritto dal: Jan 2005
Città: A casa mia
Messaggi: 825
|
ragazzi non ho parole siete mitici!!! GRAZIE MILLE!!!!!!!
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:45.





















