Extending EncapsulatedInvoke Example

Extending EncapsulatedInvoke Example

Old forum URL: forums.lhotka.net/forums/t/10126.aspx

Harry posted on Friday, March 04, 2011

I am trying to extent the EncapsulatedInvoke example to us a MS SQL database rather than the Mock and SqlCe examples that are provided.
I have created a new project called DataAccess.Sql and have pretty much coped the code from the SqlCe project making what
I thought where suitable adjustments.

My AppConfig now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!--<add key="DalManagerType" value="DataAccess.Mock.DalManager,DataAccess.Mock" />-->
<!--<add key="DalManagerType" value="DataAccess.SqlCe.DalManager,DataAccess.SqlCe" />-->
<add key="DalManagerType" value="DataAccess.Sql.DalManager,DataAccess.Sql" />
<add name="LocalDb" connectionString="Data Source=C:\Dev\csla\csla4\03-DataAccess-110221\EncapsulatedInvoke\WpfUI\LocalDb.sdf" providerName="System.Data.SqlServerCe.3.5" />
<add name="MSSQL" connectionString="Server=sunpharr;Database=SUN426;Trusted_Connection=True;" />

However the DalFactory.cs in the DataAccess project returns null for the _dalType when executing this line:

_dalType = Type.GetType(dalTypeName);

Any suggestions where I may have gone wrong.
This is the code for my DataAccess.Sql->DalManager.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.Data;
using System.Data.SqlClient;

namespace DataAccess.Sql
public class DalManager : DataAccess.IDalManager
private static string _typeMask = typeof(DalManager).FullName.Replace("DalManager", @"{0}");
public T GetProvider<T>() where T : class
var typeName = string.Format(_typeMask, typeof(T).Name.Substring(1));
var type = Type.GetType(typeName);
if (type != null)
return Activator.CreateInstance(type) as T;
throw new NotImplementedException(typeName);

public ConnectionManager<SqlConnection> ConnectionManager { get; private set; }
public DalManager()
ConnectionManager = ConnectionManager<SqlConnection>.GetManager("MSSQL");

public void Dispose()
ConnectionManager = null;

Harry replied on Saturday, March 05, 2011

Well if you look long enough you can usually answer your own question :-)

The answer is I needed to copy the new DLL DataAccess.Sql.dll into the wpfUI\debug\bin directory. Somehow in Rocky's example he seems to do this automatically, anyone know how this is done?

ajj3085 replied on Saturday, March 05, 2011

There's a few ways; one is to reference the assembly.  The other would be a post build event which manually copies the files.

RockfordLhotka replied on Saturday, March 05, 2011

In the sample solutions for the Data Access ebook I am referencing the projects, so Visual Studio copies the files into the right location.

Technically there's no need to reference the projects - assuming you have some other mechanism by which the DLL files get copied to the right folder. But (at least for demo purposes) the simplest solution is to add the reference.

Copyright (c) Marimer LLC