Wednesday, March 27, 2013

How to get distinct rows from a list using LINQ??

Let’s say that you have a list of objects that contains duplicate items and you want to extract a subset of distinct items. Just follow this code.

var TeamList = _context.tbl_user.ToList();// _context is a entity connection string
TeamList = TeamList.GroupBy(i => i.Team).Select(g => g.First()).ToList();
// OR
var distinctItems = items.GroupBy(x => x.PropertyToCompare).Select(x => x.First());



Happy Programming!!
Just because I can…

Wednesday, March 13, 2013

How found max id use LINQ?

If you want max Id from your table using LINQ then you can use bellow code.

int maxIdProd = context.Product.OrderBy(o => o.Id).Last();
// OR
var max = context.Product.Select(x=>x.ProductID).Max(); 


Enjoy!!

Thursday, March 7, 2013

how to display alert by using serverside code in asp.net C#?


If you want an alert message box in your application which returns a value. Now i am using a code for an alertmessage which returns value.
Response.Write(""); 
*Please correct spelling alert, Session["UserID"] is a server side variable .
Or
 ClientScript.RegisterStartupScript(GetType(), "TestAlert", "alert(\'This is test alert.\');", true);
Do let me know your feedback, comments.......