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