First and foremost: the t4 templates are there for you to change as needed with SS3. That was the main idea with using T4 - I don't want to back you into my silliness :).
To the question at hand - I think this might be a bug in our templates that refuses to stick a value into the PK field:
ISqlQuery BuildInsertQuery(T item) {
ITable tbl = _db.FindTable(typeof(T).Name);
Insert query = null;
if (tbl != null) {
var hashed = item.ToDictionary();
query = new Insert(_db.Provider).Into<T>(tbl); ;
foreach (string key in hashed.Keys) {
IColumn col = tbl.GetColumn(key);
if (!col.IsPrimaryKey) {
query.Value(key, hashed[key]);
}
}
}
return query;
}
In this, our check should actually be...
if (!col.IsPrimaryKey && !col.AutoIncrement) {
query.Value(key, hashed[key]);
}
In this way, the non-identity will be inserted. But in reading your issue here, it sounds to me like you're not trying to insert into a non-identity.
The email you sent me doesn't say anything about PKs as identity - your PK was a thing called "NAme" which is a string type and not and identity (auto-increment).
I'm wondering about when I cannot get around this issue--when I have to add a new record to the database and have an identity as my primary key.
This is what SubSonic assumes - that your PK is an IDENTITY column. If you ONLY have an IDENTITY column, we can't help you because this is a deadlocked table in that you can't insert any value into it, therefor you can't tick the IDENTITY column. Your only recourse at this point is to SET IDENTITY INSERT="off", which defeats the purpose.
Hopefully this will answer your question? If I'm not getting it - can you do this for me:
- One sentence: what can't you do and what's the error
- What did you expect
Thanks Will and I hope I'm not being thick.
I create what I call a "ViewModel" for each view. I put them in a folder called ViewModels in my MVC Web project. I name them after the controller and action (or view) they represent. So if I need to pass data to the SignUp view on the Membership controller I create a MembershipSignUpViewModel.cs class and put it in the ViewModels folder.
Then I add the necessary properties and methods to facilitate the transfer of data from the controller to the view. I use the Automapper to get from my ViewModel to the Domain Model and back again if necessary.
This also works well for composite ViewModels that contain properties that are of the type of other ViewModels. For instance if you have 5 widgets on the index page in the membership controller, and you created a ViewModel for each partial view - how do you pass the data from the Index action to the partials? You add a property to the MembershipIndexViewModel of type MyPartialViewModel and when rendering the partial you would pass in Model.MyPartialViewModel.
Doing it this way allows you to adjust the partial ViewModel properties without having to change the Index view at all. It still just passes in Model.MyPartialViewModel so there is less of a chance that you will have to go through the whole chain of partials to fix something when all you're doing is adding a property to the partial ViewModel.
I will also add the namespace "MyProject.Web.ViewModels" to the web.config so as to allow me to reference them in any view without ever adding an explicit import statement on each view. Just makes it a little cleaner.
Best Answer
okay i have solved the problem, but the answer is here should anyone need it or wants to know what happened.
i put my TT files into the models folder, my namesspace should have been test2.Models
however it was test2
also i needed the using directive of using test2.Models; at the top of my page.
still get an error where i have to correct the view on the inherites it puts i have to change this to
very nice now is this subsonic very very fast loading compared to other stuff i have used.
ta