views:

10

answers:

0

I love SubSonic, but it continues to bite me in the @$$. I have bumped into LINQ projection problems that I have been able to work around but this latest error that seems to have "appeared" when I added a column to the insert list.

For the sake of brevity I am not including the entire generated class here, but the relevant pieces are:

public class Genre
{
    public int GenreId { get; set; } // PK
    public string Name { get; set; }
    public string Slug { get; set; }
    public int CreatedBy { get; set; }
    public DateTime CreatedOn { get; set; }
    // Requisite Notify events.
}

I have the IQuerySurface implementation that is essentially MyNamespace.MyDatabaseDB.

When I try and execute the query generated from the following

Surface.Insert
    .Into<Genre>(g => g.Name, g => g.Slug, g => g.CreatedBy, g => g.CreatedOn)
    .Values(genre.Name, genre.Slug, genre.CreatedBy, genre.CreatedOn)

I get an exception that states: Must declare the scalar variable "@ins_Name".

The query that is executed is as follows (I reformatted for legibility but no characters were added/removed other than newlines):

exec sp_executesql 
    N'INSERT INTO [dbo].[Genre](Name,Slug,CreatedBy,CreatedOn)
    VALUES (@ins_Name,@ins_Slug,@ins_CreatedBy,@ins_CreatedOn);
    SELECT SCOPE_IDENTITY() as new_id;',
    N'@0 varchar(15),@1 varchar(14),@2 varchar(1),@3 varchar(20)',@0='This won''t work',@1='this-wont-work',@2='1',@3='6/24/2010 3:26:30 AM'

As you can see, the value parameters are "@ins_Name, @ins_Slug, ...". Essentially, @ins_{FieldName}. However, the parameters passed are ordinal values. I get the same behavior -- and I expect I would looking at the source code -- when I do something like

genre.ToInsertQuery<Genre>();

However,

Surface.Insert.Into<Genre>(g => g.Name).Values(genreName)

works.

I have rerun the templates quite a few times and I'm still stuck with this error. I'm too close to the end of the project to pull SubSonic, but I've spent way too much time trying to find work-arounds for these issues.

I'm hoping I'm doing something stupid here and someone can smack me until I see the light.