im trying to add a single row to a class using linq to sql.
i have a table (AdressesTable) wich contains a key named ID and an adress1 and adress2 column…
i created a class:
public class Adresses
{
public int ID { get; set; }
public int adress1 { get; set; }
public int adress2 { get; set; }
}
i created a datacontext and wrote a query
DBDataContext db = new DBDataContext();
Adresses adr = (from p in db.AdressesTable
where p.ID ==1
select p).First();
but it’s not working… how can i add a sql query result to a class object?
You need to build a
DbContextlike this:and then you can use it like this: