A
Andrus
Web services methods using Linq to sql contain lot of scalar queries like
decimal? result;
using (var db = new MyDataContext())
result = (from entity in db.SomeTable
where entity.Id=somevalue
select d.DecimalColum).SingleOrDefault();
To make code shorter those can also be re-written as
decimal? result = (from entity in new MyDataContext().SomeTable
where entity.Id=somevalue
select d.DecimalColum).SingleOrDefault();
In this case DataContext is not wrapped to using statement and maybe dispose
is not called.
Is it ok to use queries without using ?
Can this query simplified more ?
Andrus.
decimal? result;
using (var db = new MyDataContext())
result = (from entity in db.SomeTable
where entity.Id=somevalue
select d.DecimalColum).SingleOrDefault();
To make code shorter those can also be re-written as
decimal? result = (from entity in new MyDataContext().SomeTable
where entity.Id=somevalue
select d.DecimalColum).SingleOrDefault();
In this case DataContext is not wrapped to using statement and maybe dispose
is not called.
Is it ok to use queries without using ?
Can this query simplified more ?
Andrus.