c# - Project a DateTime from an IQueryable to a string in a custom class -


This code is run on the server part of my Silverlight application with WCF RIA services

  

code> Public IQueryable & lt; PersonePM & gt; GetPersoneByCognome {String Cognition} {Returns (object contact with P in peer) where p. Cognome Toolavar () includes (Cognome.Rim () .toolver ()) Identify the new person {ID = PIID, Cognome = P. Kogonem, Nom = P. No. Saso = P. Ismashcio == Really? "M": "F", Stringacognoni noam = p. Cognimo + + "+ P. nan, dataneticita = P. data nascita == blank? DateTime.In value: P.DataNascita.Value, Lugonescita = (P. Ishmacio == is true?" NATO A ":" Nata A " ) + P. Citta.Dinnomyagion + "(" + P. Seat. Provincia.trim ++ ")", CodisFiskel = P. Codicefiscell, Stringna Nassica = (P. ISmasccio == true? "NATO A": " Nata A ") + P. Citta.Dinnomyagion +" ("+ P. Sev. Provincia." + (P. Datanetika! = Null? (((P. Dat Nanacita.Wal Ue.Day == 1) || || (P. datanetica.value.de == 8) || (P. Datanacita.value.dea == 11))? "L" ":" IL " ) + P.DataNascita.Value: string.Empty)}); } Public Square PersonePM {[Key] Public Guide ID {get; Set; } Public string cognome {receive; Set; } Public String Nome {Received; Set; } Public string Sesso {get; Set; } Public string StringaCognomeNome {get; Set; } Receive Public Date Time Data Nation { Set; } Get the public string lugo asc (get; Set; } Public String StringaNascita {get; Set; } Public string CodiceFiscale {get; Set; }}

Due to the Italian language, I want to see the format where a person is born and when the best user is in the form of a common language for understanding. But the above code does not work because Linq-to-Entities is not able to enable a datetime for a string (the whole story is slightly different .. but let's say briefly); The error has been thrown here:

  Stringana nascita = (P. ismasscio == true? "NATO A": "Nata A") + P Cita.danniminizen + "(" + p. Sita .Provincia.Trim () + ")" + (P. datanetika! = Null? ((P. datanetica.value.de == 1) || (P. datanetica. Value.de == 8) || (P.DataNascita.Value.Day == 11) "l '": "il") + p.DataNascita.Value: string.Empty  
< P> The problem is well known and I find a different solution, but nobody to project on the custom class used as a presentation model. It's about a week, I'm working on this problem and I have not solved any solution yet. any idea?

Thank you!

Edit July 19 16.27GMT + 1

If I comment on this part

  Stringna Nassica = (P. Ishmacio == is true? "NATO A": "Nata A") + P. Cotta Dinnomyagion + "(" + P. Seat. Provincia.trim (++) "+ (P. Datanacita! = Null? ((P. Datanetica.value.de == 1) || (P. Datanetica Value. De = 8) || (P. datanetica.value.de == 11)) "L" ":" IL ") + P. datanetica. Value: string empty)  

Everything works fine.

I recommend that you get raw data from the database, and then make a string conversion later.

IQueryable & lt; T & gt; to IEnumerable & lt; T & gt; You can use - so you have:

  var dbQuery = from the data in the source where the stuff select simple projection; Var clrQuery = data in dbQuery.AsEnumerable () where client-side filters select client-side projection;  

If you see what I mean.

Note that asEnumerable () actually changes the compilation-time type of expression, so that the other pieces of question enumerable * instead of Queryable * .

.

Comments