-
LINQ for SQL unit testing Part2
I'm not really sure whether the benefits are worth it unless you need very high quality code and for larger applications. I'm not sure why i feel this and whether this is due to compartmentalizing the LINQ code or whether its just TDD on LINQ code which can be tested via a test DB i suspect its the TDD.
Still storing all the sql in the various repositories is a plus.
}
---------------------------------------------------------------------------------------------------------------------------internal class ProvinceRepositry : RepositryBase<Province>, IProvinceRepositry{public ProvinceRepositry()base(new ProvinceUnitOfWork())public ProvinceRepositry(IUnitOfWork<Province> work)base(work)#region IProvinceRepositry Memberspublic ProvinceCollection GetWorld(string worldname)throw new System.NotImplementedException();public ProvinceCollection GetWorld()throw new System.NotImplementedException();public Province Get(int id)throw new System.NotImplementedException();public void Update(Province prov)Guard.ArgumentNotNull(prov, "PROVINCE"); public...
-
LINQ for SQL unit testing Part1
Ian Cooper had some nice articles on how to do unit testing , i have implemented his code and ideas ( shown below) .
See Part 2 for some Business code
{
{
impl = source;
queryableImpl = impl.AsQueryable();
}
{
}
{
impl.Add(item);
queryableImpl = impl.AsQueryable();
}
{
}
#region
{
}
{
impl.Remove(item);
queryableImpl = impl.AsQueryable();
}
{
impl.RemoveAll(MatchWithContainer);
queryableImpl = impl.AsQueryable();
}
{
}
#endregion
#region
System.Collections.
{
}
#endregion
#region
{
}
{
}
{
}
#endregion
}
public interface IDataSource<T> : IQueryable<T>, IEnumerable<T>,ITable, IQueryProvider
{
}
{
}
public
{
}
interface IUnitOfWork<T> :IDisposableILINQDataSource<T> DataSource{ get; set; } //table// bool ReadOnly { get; set; }void SubmitChanges(); // only call for inserts OR when all work is done
{
{
unitOfWork = work;
}
{
#region
{
{
}
{
dataSource =
}
}
#region
public abstract class UnitOfWorkBase<T> : IUnitOfWork<T>ILINQDataSource<T> dataSource; IUnitofWork<T> Memberspublic ILINQDataSource<T> DataSourcegetreturn dataSource;setvalue ;abstract public bool ReadOnly { get; set; }abstract...
-
LINQ for SQL thread affinity Data context
From http://www.cnblogs.com/sunrack/articles/1130866.html , for services we use mainly Thread Context ( the original allows a static context as well ).
Thread context is very usefull for services.
{
{
TDataContext result = (TDataContext)
SetOptions(result);
}
{
TDataContext result = (TDataContext)
SetOptions(result);
}
{
options.LoadWith<
context.LoadOptions = options;
}
{
}
{
}
{
key =
context =
{
context = GetDataContext();
context = GetDataContext(ConnectionString);
{
threadData =
}
}
}
{
}
{
}
{
}
}
///<summary>/// This class provides several static methods for loading DataContext objects /// in a variety of ways. You can load the data context as normal one new instance/// at a time, or you can choose to use one of the scoped factory methods that/// can scope the DataContext to a WebRequest or a Thread context (in...
-
OO with services
Are OO code and SOA diametrically opposed ? In a lot of ways this is true services tend to produce very anemic object models however this merely reduces reuse which is a myth in OO for the majority anyway .
However services have a unique but familiar problem . The contract of the service is critical it needs to be designed for
- The ease of use of the client
- For performance ( ie chunky calls , many small calls can bring many services down to its needs)
- To be upgradeable and allow backward compatibility.
- Compatible with an...
-
How to write a good service contracts
... not hand craft wsdl
Custom messages reduce churn and change in the contract
Lets say you have this datacontract
[DataContract]
public class WorkEntry
{
[DataMember]
public DateTime StartTime;
[DataMember]
public TimeSpan Duration;
[DataMember]
public string User;
[DataMember]
public string CostCentre;
[DataMember]
string Comments;
}
What can go wrong here ? Using public fields is good , its tight and if you need to do custom things you can refactor it easily. I think there is nothing really wrong here however if this is a business object also i would be concerned.
The big gotcha maybe DateTime , lets say you have some other systems in your company that use Java . Now Java systems...
-
LINQ for SQL and reattaching objects in nTier scenarios
One of the issues that keeps cropping up is LINQ for SQLs support for nTier scenarios and having to reattach the object to the DataContext.
However this problem is exhibited by all ORMs in nTier scenarios ( though not in web sites) and you basically have 2 choices
- refetch the object from cache/DB and replay all changes to see what has changed then you can craft a custom Update to just change the items changed.
- update all fields in the DB.
While the 2nd method is easier the first is more efficient especially when you consider that it...
-
Is LINQ for sql dead
There were a lot of comments about the supposed demise of LINQ for SQL people expected it to evolve into a nHibernate style framework (and rightly object to EF Entity Frameworks change tracking http://weblogs.asp.net/fbouma/archive/2008/11/21/baby-sitter-framework-2-0-change-tracking-in-the-ef-v2-it-s-still-your-problem.aspx ) .
I think people miss the point here , LINQ for SQL is and always will be a light weight solution for smaller or RAD style projects. As Damian Guard ( from the LINQ for SQL team ) explains it will be maintained and changes required by the community will be implemented. http://damieng.com/blog/2008/10/31/linq-to-sql-next-steps. As it is now it is fine for most current and future needs....
-
Are Datasets dead
Can anyone see a use for Datasets these days ? LINQ for SQL seems to have all the bases covered with a much easier and extensible model.
-
Simple services and Linq for SQL - match made in heaven
Im a pretty big fan of Linq for SQL and it works so well with services especially smaller ones ( especially when there are no updates) .
The fact services are normally responsible for about 3 tables /conceptual domain classes mean you can quickly drag the 3 tables onto the designer and generate the code. If the structure changes you just recreate the data.
Lightweight data
Light weight service
Light weight testing
Light weight procedural code. .
These services are quick to write and easy to maintain,