asp.net - how to assign value to entity got from database -


i have linq query below:

public iqueryable<vmemp> getemp(int crewid)     {         var dt = new empentities();         var e = t in dt.tblemp                 (t.crewid == crewid)                 select new vmemp                 {                     id = -1,                     crew = t.crewid,                     name = t.name,                     address = t.address                 };         return e;         } 

i hope can make id auto decrease 1 till end of employee. first's id -1, second's -2, third -3 ...

how here? lot

use counter variable , decrease every record while project custom poco.

public iqueryable<vmemp> getemp(int crewid) {     int counter=0;     var dt = new empentities();      //load items list of anonymous type     var elist = t in dt.tblemp             (t.crewid == crewid)             .select(s=>               new  { id = 0,                      crew = s.crewid,                      name = s.name,                      address = s.address                   }).tolist();      var e=elist.select(x=> new vmemp             {                 id = --counter,                 crew = x.crew,                 name = x.name,                 address = x.address             });     return e.asqueryable();  } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -