Call Local Function in LInq Query - Linq

Jul 12, 2019 BY xtreme
Call function in 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,
			source = x.source != null ? GetSource(x.source.Value) : "",
		}).FirstOrDefault();

		return result;
	}
     public string GetSource(int id)
    {
        switch (id)
        {
            case 1: return "SearchEngine";
            case 2: return "Friend";
            case 3: return "ExteranlAds";
        }
    }
}
Related