For the scaffolding to work I had to:
1. copy %programfiles%\T4 Toolbox\T4Toolbox\ to C:\Projects
\FordVehicleProductionTracking\tools\CrudScaffolding\
2. copy %programfiles%\T4 Toolbox\T4Toolbox.tt to C:\Projects
\FordVehicleProductionTracking\tools\CrudScaffolding\
Perhaps whatever technique you use to figure out if/where T4 Toolbox
is installed needs to be verified or at least some error checking that
screams "Hey! I cannot find where you installed T4 Toolbox".
I am also seeing some (nice as it turns out because you already auto-
generate a lot of the necessary code) mismatches with what needs to be
done to use Fluent NHibernate in Appendix B vs. what I actually ended
up doing. Some of the steps called for seem to have already been
performed while others, like how to modify RouteRegister are still
unclear to me.
In my simple example, I have a SQL Server database with one table
named BodyStyle defined thusly:
CREATE TABLE [dbo].[BodyStyle](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Description] [varchar](50) NOT NULL,
[BodyCode] [char](3) NOT NULL,
[OrderCode] [char](4) NOT NULL,
[IsHybrid] [bit] NOT NULL,
CONSTRAINT [PK_BodyStyle] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
The corresponding one-time scaffolding I performed via the tt tool
looks like this:
EntityScaffoldingDetails entityScaffoldingDetails =
new EntityScaffoldingDetails("BodyStyle");
/*
* Property names should be PascalCase.
* Do not include a property for Id as it will be included
automatically.
*/
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("Description", "string", string.Empty,
"[NotNull, NotEmpty]", false)
);
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("BodyCode", "string", string.Empty, "[NotNull,
NotEmpty]", false)
);
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("OrderCode", "string", string.Empty, "[NotNull,
NotEmpty]", false)
);
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("IsHybrid", "bool", false, "[NotNull]", false)
);
///////////////////////////////////////////////////
// The first parameter should reflect the root directory of your
solution
ScaffoldingGenerator generator = new ScaffoldingGenerator(
@"C:\Projects\FordVehicleProductionTracking\",
"FordVehicleProductionTracking", entityScaffoldingDetails);
Everything works fine until I run the NUnit test named
CanConfirmDatabaseMatchesMappings in MappingIntegrationTests, which
never gets passed the Setup step, which is defined as:
[SetUp]
public virtual void SetUp()
{
string[] mappingAssemblies =
RepositoryTestsHelper.GetMappingAssemblies();
NHibernateSession.Init(new SimpleSessionStorage(),
mappingAssemblies,
new AutoPersistenceModelGenerator().Generate(),
"../../../../app/FordVehicleProductionTracking.Web/
NHibernate.config");
}
And results in the following error:
An exception occurred during configuration of persistence layer.
The NHibernate.config file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Data
Source=.;Database=FordVehicleProductionTracking;Integrated
Security=True;MultipleActiveResultSets=True;</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</
property>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
<property name="show_sql">false</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
<!-- Mapping assemblies -->
<!-- Can't map it for Fluent NHibernate here; instead, load the
mapping assembly in Global.asax.cs.
If you're still using HBMs, you can use the mapping here or pass
the assembly via Global.asax.cs
as well, just like you can do with the Fluent NHibernate assembly
(s). -->
<!-- mapping assembly="FordVehicleProductionTracking.Data" -->
</session-factory>
</hibernate-configuration>
I'll try the uninstall/reinstall sequence you suggest and see if that
affects anything.
Eventually, when the unit tests start working, I'll see if I can
unravel the mystery of Routes, which I presently have set up as
follows, based on the auto-generated BodyStylesController.cs and the
auto-generated BodyStyle.cs classes:
namespace FordVehicleProductionTracking.Web.Controllers
{
public class RouteRegistrar
{
public static void RegisterRoutesTo(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?
favicon.ico(/.*)?" });
// The areas below must be registered from greater
subareas to fewer;
// i.e., the root area should be the last area registered
routes.CreateArea("BodyStyle",
"FordVehicleProductionTracking.Web.Controllers.BodyStylesController",
routes.MapRoute(null, "BodyStyle/{controller}/
{action}", new { action = "Index" }),
routes.MapRoute(null, "BodyStyle/{controller}/{action}/
{id}")
);
// Routing config for the root area
routes.CreateArea("Root",
"FordVehicleProductionTracking.Web.Controllers",
routes.MapRoute(null, "{controller}/{action}", new
{ controller = "Home", action = "Index" })
);
}
}
}
I'm really beginning to appreciate the huge amount of heavy lifting
you've done. It's pretty fantastic, even when compared to ASP.Net
Dynamic Data, which is wedded to Microsoft's proprietary Linq To SQL
and EF technologies. It's nice to have the alternative to use
NHibernate + Fluent-NHibernate with ASP.Net MVC.
P.S. The example I wrote is not something I built for Ford. I was
forced to wait six months to get my new 2009 Ford Escape Hybrid, so I
wrote a small tracking system while I was waiting and used Microsoft's
ASP.Net Dynamic Data architecture to make data entry easier. Now I
want to see if I can move it over to S#harp Architecture so I can
compare the two.
> > scaffolding?- Hide quoted text -
>
> - Show quoted text -