I have downloaded any samples of usage that I can find but there does
not appear to be a working sample of the LinqToSql other then unit
tests using Mock's.
I have not been able to get LinqToSql working, I am using Windsor
Container, which I am also new too. Here is my code.
Register the interfaces that I believe I need:
IWindsorContainer container = new WindsorContainer();
container.Register(Component.For(typeof(IRepository<>)).ImplementedBy(typeof(LinqToSqlRepository<>)).LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<ITransaction>().ImplementedBy<LinqToSqlTransaction>().LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<IUnitOfWork>().ImplementedBy<LinqToSqlUnitOfWork>().LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<IUnitOfWorkFactory>().ImplementedBy<LinqToSqlUnitOfWorkFactory>().LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<IQuoteRequestRepository>().ImplementedBy<QuoteRequestRepositoryInLinq>().LifeStyle.Is(LifestyleType.Transient));
LinqToSqlUnitOfWorkFactory.SetDataContextProvider(() =>
{
var context = new CarInsuranceDataContext
{ DeferredLoadingEnabled = true };
return context;
});
My Repository
public class QuoteRequestRepositoryInLinq :
LinqToSqlRepository<QuoteRequest>, IQuoteRequestRepository
{
}
Try to get a Repository
using (IocUtil.GetInstance<IUnitOfWork>())
{
var respository =
IocUtil.GetInstance<IQuoteRequestRepository>();
foreach (var item in respository)
{
_.Print(item.ToEntityString(0, " "));
}
}
Exception
CarInsurance.Test.QuickTest.ShouldResolveRequestedTypeFromUnderlyingContainer:
Microsoft.Practices.ServiceLocation.ActivationException : Activation
error occured while trying to get instance of type IUnitOfWork, key ""
----> Castle.MicroKernel.Handlers.HandlerException : Can't create
component 'NCommon.Data.LinqToSql.LinqToSqlUnitOfWork' as it has
dependencies to be satisfied.
NCommon.Data.LinqToSql.LinqToSqlUnitOfWork is waiting for the
following dependencies:
Services:
- NCommon.Data.LinqToSql.ILinqSession which was not registered.
I cannot register ILinqSession because it the implementation is
internal.
We are starting the project this week so I hope someone can help.
Cheers Dave
--
You received this message because you are subscribed to the Google Groups "ncommon" group.
To post to this group, send email to nco...@googlegroups.com.
To unsubscribe from this group, send email to ncommon+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ncommon?hl=en.
I had some issues getting things to work and would just like to go
over them.
1. What is the conceptual difference between UnitOfWork and
UnitOfWorkScope ?
2. The example you give for UnitOfWork.Create does not work because
there is no factory method called Create on this class, I tried
following code but it failed.
using ((new LinqToSqlUnitOfWorkFactory()).Create())
{
//var respository =
IocUtil.GetInstance<IQuoteRequestRepository>();
var respository = new
LinqToSqlRepository<QuoteRequest>();
foreach (var item in respository)
{
_.P(item.ToEntityString(0, " "));
}
}
System.InvalidOperationException : No compatible UnitOfWork instance
was found. Please start a compatible unit of work before creating the
repository or use the constructor overload to explicitly provide a
ObjectContext.
I'm wondering still what the best pattern is to use with LinqToSql.
Do you have a sample application that uses LinqToSql with Windsor, I
know you have one for entity framework.
Cheers Dave
Do you need to do a scope.Commit for queries, code seams to work if I
comment out the Commit but I was wondering if they were implications
of not committing.
using (var scope = new UnitOfWorkScope())
{
var respository =
Ioc.GetInstance<IQuoteRequestRepository>();
foreach (var item in respository)
{
_.P(item.ToEntityString(0, " "));
}
//scope.Commit();
}
Dave
2. The example you give for UnitOfWork.Create does not work because
there is no factory method called Create on this class, I tried
following code but it failed.
using ((new LinqToSqlUnitOfWorkFactory()).Create())
{var respository = new
//var respository =
IocUtil.GetInstance<IQuoteRequestRepository>();
LinqToSqlRepository<QuoteRequest>();
_.P(item.ToEntityString(0, " "));
foreach (var item in respository)
{
}
}
System.InvalidOperationException : No compatible UnitOfWork instance
was found. Please start a compatible unit of work before creating the
repository or use the constructor overload to explicitly provide a
ObjectContext.
I'm wondering still what the best pattern is to use with LinqToSql.
Do you have a sample application that uses LinqToSql with Windsor, I
know you have one for entity framework.
Dave