Select, verify

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.