public ActionResult Index()
{
SampleEntities obj = new SampleEntities();
int Id = 2;
var memList = (from x in obj.Memberships where x.ID == Id select x).First();
return View();
}
--------------------
- FirstOrDefault method Returns the First element of a sequence, or a default value if the Sequence contains no elements.
- Returns null if it does not contain any element.
Example:-
-------------
public ActionResult Index()
{
SampleEntities obj = new SampleEntities();
int Id = 2;
var memList = (from x in obj.Memberships where x.ID == Id select x).FirstOrDefault();
return View();
}
In the above Code, We use Index Action method and used FirstOrDefault() and When Id=2 match with database then it will return the result otherwise it Will return null and Which is Shown in below figure,
0 comments:
Post a Comment