In Users model, I have DateTime dtContractStart and DateTime dtContractEnd.
In UserModel model, I have String dtContractStart and String dtContractEnd.
To can perform a string cast with Linq query, I want to try something like that :
DateTime start;
DateTime end;
var users = DB.Users
.Select(user => new UserModel
{
id = user.id,
firstname = user.firstname,
lastname = user.lastname,
dtContractStart = "",
dtContractEnd = "",
}
&& start = user.dtContractStart
&& end = user.dtContractEnd
)
.ToList();
users.ForEach(user =>
user.dtContractStart = start.toString() &&
user.dtContractEnd = end.toString()
);
Is it possible? I don’t find the good syntax.
If the Linq provider you’re using doesn’t accept the call to
ToString, you can execute your query in two steps, usingAsEnumerableto force the query execution: