1) Definition of projection (select): Create an object in the query
In
Var result = _ db. mycontext. where (a =>. id = id ). select (new {. id,. name,. createtime}) foreach (var c in result) {Console. writeline (result .);}
Why is the output shown in figure
{Id = 001, name = "benjamin", createtime = "20121027 "}
{Id = 002, name = "John", createtime = "20121011 "}
{Id = 003, name = "Chris", createtime = "20121018 "}
? Do not even need to rewrite the ToString () method?
The reason is that the compiler has provided the default Execution Code for anonymous objects and output the attribute name and value in a way similar to object initialization.
2) use FirstOrDefault () -- can simplify where + select filtering
3) The UpdateModel (model) and TryUpdateModel (model) methods can automatically update the passed data (form, querystring, etc.) to a model that matches the same attributes.
This can be used when a new model is created.
4) How to Use ModelState Verification:
1. Add the following features to the related attributes of the form: [Required]
2. Add
@ Html. ValidationMessageFor (model => model. Name)
3. Use ModelState. IsValid on the server side for verification.