I am new to linq and linq2SQL. I have done my homework, i.e. found many results and answers that target similar problems. Seemingly lacking deeper understanding of linq and linq2SQL I am at my wits end.
I have a web application with a simple html and js frontend. I exchange data with my aspx via ajax xmlhttprequests. All the data naturally comes in and is supposed to go out as strings.
What I am trying to do:
private DateTime _date;
[Column(Storage = "_date", Name = "date", DbType = "date", CanBeNull = false)]
public string date
{
get { return this._date.ToString("yyyy-MM-dd"); }
set { this._date = DateTime.ParseExact(value, "yyyy-MM-dd", null); }
}
Instead of converting the string to a datetime in my aspx I would like to just pass on the strings and do the conversion at get and set. Running this code gives me an “invalid cast” error.
Am I trying to do something that is by desing simply not supposed to be done? Is my approach wrong? I don’t expect someone else to write the code for me. I don’t mind digging in the references, but I don’t know where to start. So if someone where to point me in the right direction, I would greatly appreciate it.
Solution for now:
Apperently linq or “whoever” is responsible can figure the casting out on it’s own, if you let it. Right now that’s good enough for me.
I have the feeling I will run into simliar casting problems later on and that different solutions may be required. If so I will update this thread.