Web-side Program trivia

Source: Internet
Author: User

One, LinQ distinct a field to go heavy

New class Goodsidcomparer, inheriting Iequalitycomparer<goods>, implementing the Equals method

 Public classGoodsidcomparer:iequalitycomparer<goods>        {             Public BOOLEquals (Goods x, Goods y) {if(x = =NULL)                    returny = =NULL; returnX.gproducer = =Y.gproducer; }             Public intGetHashCode (Goods obj) {if(obj = =NULL)                    return 0; returnobj.            Gproducer.gethashcode (); }}//Depending on the origin ( gproducer) Go heavy

When you use it, you only need to

var distinctgoods= allgoods.distinct (New Goodsidcomparer ()); //need to reference a namespace

Second, the MVC controller controllers using the using direct call database combination query

  In the MVC controller controllers, use the using direct call database composition query, and return to the view should be noted as:

  Return View (New list<goods> (All));

  

using New Fruitdatacontext ())            {                var all = con. Goods.asenumerable ();                 if "" )                {                    var Category = con. Goods.where (r = r.gcategory = = category)                    ; = All.intersect (Category);                }            }             return View (new list<goods> (All));    

A strong type is referenced in the view:

  @model list<goods>

Third, the maximum value of the self-increment column ID in the LINQ query database

         Public int Maxid ()        {            return con. Goods.max (r=>r.gids);        }

Web-side Program trivia

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.