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...

IQueryable Vs IEnumerable in Linq Query- Linq

Jul 10, 2019 BY xtreme

IEnumerable is inherited by IQueryable, Hence IQueryable has all the features of IEnumerable besides own. IEnumerable1. IEnumerable doesn’t move between items, it is a forward-only cursor over a collection. 2. While query data from a database, IEnumerable execute a select query on the server s...

Format Data in LInq Query- Linq

Jul 10, 2019 BY xtreme

Format Date while getting data via Linq public 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, add...