Scott Gu Dynamic Linq Convertir fecha y hora en fecha y hora cortas

I am using the Scott Gu Dynamic Linq class and I am trying to convert a datetime to return a short datetime before databinding the result set to a gridview in Now, I know that I can go through the gridview row databound event and check each cell to see if it is a date, and if it is, convert the date to the shortdate, however that is very cumbersome and I do not feel it is very efficient.

I am building my select statement in DynamicLinq as follows:

Filter gets its information as follows:

 foreach (KeyValuePair<string,string> kvp in dictFilters)
            filter += kvp.Key + " as " + kvp.Value.Replace("-", "_").Replace(" ", "_") + ",";

        var result = db.ViewADHOCContractInfos.Select("new(" + filter + ")");

which gives me the result set of:

    {SELECT [t0].[dtmAward] AS [Award_Date], [t0].[guidFromId],  [t0].[strFundingNumber] AS [Funding_Number], [t0].[dtmCertified] AS [Certified_Date], [t0].[strFundingNumberStatus] AS [Funding_Status]
FROM [dbo].[ViewADHOCInfo] AS [t0]

Ahora lo que quiero es esto:

   {SELECT Convert(VarChar, [t0].[dtmAward], 101) AS [Award_Date], [t0].[guidFromId],  [t0].[strFundingNumber] AS [Funding_Number], [t0].[dtmCertified] AS [Certified_Date], [t0].[strFundingNumberStatus] AS [Funding_Status]
FROM [dbo].[ViewADHOCInfo] AS [t0]

Is it possible to add a SQL convert to by select statement using Dynamic Linq?

preguntado el 28 de agosto de 12 a las 14:08

@Icarus -, I will add that, sorry -

What LINQ provider do you use? Because I only know how to do this with NHibernate and dynamic Linq. -

@PatrickKoorevaar I am using the regular LINQ library and have all of my tables connected to a DBML. I am using the Dynamic Linq class provided by Scott Gu -

1 Respuestas

Yours is a formatting issue:

Simply set the DataFormatString property on the column as so:


El contexto completo:

<asp:BoundField DataField="DateColumn" 
                    DataFormatString="{0:MM/dd/yy}" />

Or to any suitable format for your case and the date will be formatted properly.

Respondido 28 ago 12, 14:08

the columns are built on the fly, there is no definition of them - EvanGWatkins

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.