The following LINQ query is giving me {1/1/0001 12:00:00 AM} for the date value instead of the date the database shows. When I copy / paste the query generated from LINQ in the debugger into SQL Management Studio, it returns the proper value.
Here is the LINQ statement:
from ga in db.GrantAgreement_Views where ga.ID.Equals(id)
&& ga.Project_Start_Date.HasValue
&& ga.Project_End_Date.HasValue
select new GAData(Convert.ToInt32(ga.ID), Convert.ToInt32(ga.Request_Amount), Convert.ToInt16(ga.Term), Convert.ToString(ga.Project_Start_Date.ToString()), Convert.ToDateTime(ga.Project_End_Date), Convert.ToString(ga.Project_Title.ToString()), (string)ga.Staff_ID.ToString(), (string)ga.Legal_Name.ToString())
Thanks for any help anyone can offer.
This is what is being passed in to SQL:
SELECT CONVERT(Int,[t0].[ID]) AS [id], CONVERT(Int,[t0].[Request_Amount]) AS [amount], CONVERT(Int,CONVERT(SmallInt,[t0].[Term])) AS [grantterm], CONVERT(NVarChar(MAX),[t0].[Project_Start_Date]) AS [start], [t0].[Project_End_Date] AS [end], CONVERT(NVarChar(MAX),[t0].[Project_Title]) AS [project], CONVERT(NVarChar(MAX),[t0].[Staff_ID]) AS [staffid], CONVERT(NVarChar(MAX),[t0].[Legal_Name]) AS [orgname]
FROM [dbo].[GrantAgreement_View] AS [t0]
WHERE ([t0].[ID] = @p0) AND ([t0].[Project_Start_Date] IS NOT NULL) AND ([t0].[Project_End_Date] IS NOT NULL)
When this is executed in SQL man studio - i get the proper results.
Here is my data struct:
public class GAData
{
public GAData() { }
public GAData(int id, int amount, int grantterm, DateTime start, DateTime end, string project, string staffid, string orgname)
{ ID = id; AMOUNT = amount; grantterm = GRANTTERM; start = START; end = END; PROJECT = project; STAFFID = staffid; orgname = ORGNAME; }
public int ID;
public int AMOUNT;
public int GRANTTERM;
public DateTime START;
public DateTime END;
public string PROJECT;
public string STAFFID;
public string ORGNAME;
}