Insert Error When Saving to a View

Posts   
 
    
IObject
User
Posts: 35
Joined: 06-Jul-2006
# Posted on: 12-Sep-2006 18:17:50   

I'm attempting to do an insert on a view in my database and the resulting sql that llbl generates is incorrect and is causing a sql exception. Below is my test code and the error that i'm getting.

//creating a new quickadd entity
EmployeeQuickAddEntity employee = new EmployeeQuickAddEntity();
//set the values the user entered;
            employee.Ssn = _sSN;
            employee.LastName = _lastName;
            employee.FirstName = _firstName;
            employee.Initial = _initial;
            employee.Active = _active;
            employee.BranchName = _branchName;
            employee.PhoneNumber = _phoneNumber;
            employee.Address = _address;
            employee.Address2 = _address2;
            employee.City = _city;
            employee.Zip = _zip;
            employee.State = _state;
            employee.MaritalStatus = _maritalStatus;
            employee.StateExemptions = Convert.ToByte(_stateExemptions);
            employee.FederalExemptions = Convert.ToByte(_federalExemptions);
            employee.TaxModel = _taxModel;
            employee.CountyJuris = _countyJuris;
            employee.CityJuris = _cityJuris;
            employee.SchoolJuris = _schoolJuris;
            employee.County = _county;
            employee.SchoolDistrictCode = _schoolDistrictCode;
            employee.SchoolTaxExempt = _schoolTaxExempt;
            employee.CityTaxExempt = _cityTaxExempt;
            employee.CountyTaxExempt = _countyTaxExempt;
            //get adapter ready
            DataAccessAdapter adapter = new DataAccessAdapter();
            //save the entity ---this is where it throws the error
            adapter.SaveEntity(employee,true);
            _aIdent = employee.Aident;

and the sql code that is getting sent to the sql server


declare @p3 int
set @p3=NULL
exec sp_executesql N'INSERT INTO [tworks].[dbo].[Employee] ([SSN], [LastName], [FirstName], [Initial], [Active], [BranchName], [PhoneNumber], 
[Address], [Address2], [City], [Zip], [State], [MaritalStatus], [StateExemptions], [FederalExemptions], [TaxModel], [CountyJuris], 
[CityJuris], [SchoolJuris], [County], [SchoolDistrictCode], [SchoolTaxExempt], [CityTaxExempt], [CountyTaxExempt])  VALUES (@Ssn, @LastName, 
@FirstName, @Initial, @Active, @BranchName, @PhoneNumber, @Address, @Address2, @City, @Zip, @State, @MaritalStatus, @StateExemptions, 
@FederalExemptions, @TaxModel, @CountyJuris, @CityJuris, @SchoolJuris, @County, @SchoolDistrictCode, @SchoolTaxExempt, @CityTaxExempt, 
@CountyTaxExempt);SELECT @Aident=',N'@Aident int output,@Ssn int,@LastName varchar(50),@FirstName varchar(50),@Initial varchar(10),@Active 
bit,@BranchName varchar(25),@PhoneNumber varchar(255),@Address varchar(50),@Address2 varchar(50),@City varchar(50),@Zip varchar(10),@State 
varchar(5),@MaritalStatus char(1),@StateExemptions tinyint,@FederalExemptions tinyint,@TaxModel varchar(10),@CountyJuris 
varchar(10),@CityJuris varchar(10),@SchoolJuris varchar(10),@County varchar(30),@SchoolDistrictCode int,@SchoolTaxExempt bit,@CityTaxExempt 
bit,@CountyTaxExempt bit',@Aident=@p3 
output,@Ssn=0,@LastName='testlastname',@FirstName='testfirstname',@Initial='',@Active=1,@BranchName='Memphis 
SE',@PhoneNumber='555.555.5555',@Address='test streeet 1',@Address2='',@City='test 
city',@Zip='',@State='',@MaritalStatus='S',@StateExemptions=0,@FederalExemptions=0,@TaxModel='EIC',@CountyJuris='', @CityJuris='',@SchoolJuris='',@County='',@SchoolDistrictCode=0,@SchoolTaxExempt=0,@CityTaxExempt=0, @CountyTaxExempt=0
select @p3

and the error from the sql server

Incorrect syntax near '='.

please let me know if I need to provide more details.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 12-Sep-2006 21:05:38   

Not sure there, but it seems it has to do with your id field, maybe around "...SELECT @Aident=',N'...".

Can you provide the table creation script?

IObject
User
Posts: 35
Joined: 06-Jul-2006
# Posted on: 12-Sep-2006 21:33:05   

this is running off a View, but here is the script for the AIdent field:

AIdent int NOT NULL IDENTITY(1,1) Primary Key,

if you like i can post the 178 fields that are on this table (not all are mapped on my object)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 12-Sep-2006 22:18:03   

Please switch on DQE tracing and paste the query generated instead of this query.

Frans Bouma | Lead developer LLBLGen Pro
IObject
User
Posts: 35
Joined: 06-Jul-2006
# Posted on: 12-Sep-2006 23:49:25   

this is what was displayed in the output window with trace enabled

Generated Sql query: 
    Query: INSERT INTO [tworks].[dbo].[Employee] ([SSN], [LastName], [FirstName], [Initial], [Active], [BranchName], [PhoneNumber], [Address], [Address2], [City], [Zip], [State], [MaritalStatus], [StateExemptions], [FederalExemptions], [TaxModel], [CountyJuris], [CityJuris], [SchoolJuris], [County], [SchoolDistrictCode], [SchoolTaxExempt], [CityTaxExempt], [CountyTaxExempt])  VALUES (@Ssn, @LastName, @FirstName, @Initial, @Active, @BranchName, @PhoneNumber, @Address, @Address2, @City, @Zip, @State, @MaritalStatus, @StateExemptions, @FederalExemptions, @TaxModel, @CountyJuris, @CityJuris, @SchoolJuris, @County, @SchoolDistrictCode, @SchoolTaxExempt, @CityTaxExempt, @CountyTaxExempt);SELECT @Aident=
    Parameter: @Aident : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Output. Value: <undefined value>.
    Parameter: @Ssn : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 0.
    Parameter: @LastName : AnsiString. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "testerl".
    Parameter: @FirstName : AnsiString. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "tester".
    Parameter: @Initial : AnsiString. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @Active : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: False.
    Parameter: @BranchName : AnsiString. Length: 25. Precision: 0. Scale: 0. Direction: Input. Value: "Memphis SE".
    Parameter: @PhoneNumber : AnsiString. Length: 255. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @Address : AnsiString. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @Address2 : AnsiString. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @City : AnsiString. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @Zip : AnsiString. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @State : AnsiString. Length: 5. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @MaritalStatus : AnsiStringFixedLength. Length: 1. Precision: 0. Scale: 0. Direction: Input. Value: "S".
    Parameter: @StateExemptions : Byte. Length: 1. Precision: 3. Scale: 0. Direction: Input. Value: 0.
    Parameter: @FederalExemptions : Byte. Length: 1. Precision: 3. Scale: 0. Direction: Input. Value: 0.
    Parameter: @TaxModel : AnsiString. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "EIC".
    Parameter: @CountyJuris : AnsiString. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @CityJuris : AnsiString. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @SchoolJuris : AnsiString. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @County : AnsiString. Length: 30. Precision: 0. Scale: 0. Direction: Input. Value: "".
    Parameter: @SchoolDistrictCode : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 0.
    Parameter: @SchoolTaxExempt : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: False.
    Parameter: @CityTaxExempt : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: False.
    Parameter: @CountyTaxExempt : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: False.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Sep-2006 07:51:46   

Do you have a PK defined for your view, in the LLBLGen Pro Designer?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 13-Sep-2006 09:38:52   

Also, what's the LLBLGen Pro version you're using, the runtime lib version (rightclick ormsupportclasses dll in explorer -> properties -> version tab)

The entity is mapped on a view, you've set the Aident field as an identity/sequenced field in the designer? If so, what's the SEQUENCE selected for Aident? If you look in the fields grid of the entity, in the last column at the right, for field Aident, what's displayed as identity sequence name?

Frans Bouma | Lead developer LLBLGen Pro
IObject
User
Posts: 35
Joined: 06-Jul-2006
# Posted on: 13-Sep-2006 16:51:38   

llbl Version 2. ormsupportclasses version 2.0.0.60701.

AIdent is set as: Identity, Read Only, Is Part of Primary Key.

Nothing is selected for Sequence.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 13-Sep-2006 17:41:52   

IObject wrote:

llbl Version 2. ormsupportclasses version 2.0.0.60701.

AIdent is set as: Identity, Read Only, Is Part of Primary Key.

Nothing is selected for Sequence.

Please select a sequence from the dropdownlist and re-generate the code. This fixes the problem.

Frans Bouma | Lead developer LLBLGen Pro
IObject
User
Posts: 35
Joined: 06-Jul-2006
# Posted on: 13-Sep-2006 17:54:47   

that worked perfectly! thank you!