Condition check in Linq Query- Linq

Jul 13, 2019 BY xtreme

Check if Match Foundpublic Student GetStudentDetails(int id) { using (DbContextModel _db = new DbContextModel()) { var result = _db.student.Where(x => x.is_active && !x.is_deleted).Select(x => new StudentModel { id = x.id, mode = x.status.ToString().Contains("paid") ...

Aggregate methods in Linq Query - Linq

Jul 13, 2019 BY xtreme

1. ANY Method Returns a Boolean value. Returns True even if a single element satisfies the condition. Return False if none of the elements satisfies the condition.. Linq to sqlpublic bool CheckStudents() { bool check = false; using (DbContextModel _db = new DbContextModel()) ...

Call Local Function in LInq Query - Linq

Jul 12, 2019 BY xtreme

Call function in Linqpublic Student GetStudentDetails(int id) { using (DbContextModel _db = new DbContextModel()) { var result = _db.student.Where(x => x.is_active && !x.is_deleted).Select(x => new StudentModel { id = x.id, source = x.source != null ? GetSource(x.sou...

Calculation in Linq Query- Linq

Jul 11, 2019 BY xtreme

Compute Sum via Linqpublic Student GetStudentDetails(int id) { using (DbContextModel _db = new DbContextModel()) { var result = _db.student.Where(x => x.is_active && !x.is_deleted).Select(x => new StudentModel { id = x.id, total = x.payments.Where(p => p.id == x.i...

Casting in Linq Query - Linq

Jul 11, 2019 BY xtreme

Cast double via Linqpublic Student GetStudentDetails(int id) { using (DbContextModel _db = new DbContextModel()) { var result = _db.student.Where(x => x.is_active && !x.is_deleted).Select(x => new StudentModel { id = x.id, amount = _db.payments.Select(z => (double...

Update Single, Multiple Records - Linq

Jul 11, 2019 BY xtreme

Update Single Record public int Update(StudentData data) { using (DbContextModel _db = new DbContextModel()) { student _student = _db.student.Find(data.id); _student.name = data.name; _db.SaveChanges(); return _student.id; } }Update Multiple Recordspublic void Update(Stude...

Get Multiple, Single, Conditional Records - Linq

Jul 11, 2019 BY xtreme

Get list of records from database public List<Student> GetStudents() { using (DbContextModel _db = new DbContextModel()) { var result = _db.student.Where(x => x.is_active && !x.is_deleted).Select(x => new StudentModel { id = x.id, name = x.name, statu...