c# - Can someone help me understand the following line? -
public team getteambyid(int id) { team team = ctx.teams.include("login").include("people").include("school").where(x => x.id == id && this.schoolslist.contains(x.school_id)).firstordefault(); /// } ctx dataaccess obbject , schoolslist dataaccess property of type list. understsand part says x => x.id == id, part this.schoolslist.contains(x.school_id) makes no sense me. know x => x.id == id returns team objects match id passed in argument, how this.schoolslist.contains(x.school_id) work? how can able use school_id property (which property of team class)?
is first part of predicate (x => x.id == id) returning team object, , second part using returned object's school id? reason seems weird way things working since kinda thought in where() method taken returned something, instead of each condition returning something.
team team = ctx.teams .include("login") .include("people") .include("school") .where(x => x.id == id && this.schoolslist.contains(x.school_id)) .firstordefault(); with line retrieving first element of ctx.teams meets requirements imposed where clause
ctx.teams here calling table teams database through ctx
the include statements used join other tables join in sql , retrieves data within joined table.
.where(x => x.id == id && this.schoolslist.contains(x.school_id)) here filtering table data line has id variable id , inside schoolslist.
firstordefault(); retrieves first item inside iqueryable returned where clause.
this can translated to:
team team = ctx.teams .include(x => x.login) .include(x => x.people) .include(x => x.school) .firstordefault(x => x.id == id && this.schoolslist.contains(x.school_id)); includes written less buggy , more oop. need following namespace system.data.entity.
** edit 1 **
i sort of understand not completely. how know x.school_id is? thought had included in question, edited in, , argument passed function "id." value of x.school_id passed contains coming from? team object returned condition x.id == id? – frostystraw
because where clause or firstordefault iteration sql through ctx.teams class of teams contains property school_id.
this possible entityframework, table represented class , class properties table columns.
ah! , when this.schoolslist.contains(x.school_id) calling list schoolslist on each "sql iteration" caused where.
it's doing:
list<team> teams = ctx.teams .include("login") .include("people") .include("school") .tolist(); team team = null; foreach (var item in teams) { if (item.id == id && this.schoolslist.contains(item.school_id)) { team = item; break; } }
Comments
Post a Comment