Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> KeyNotFoundException on CF 3.5
 

Pages: 1
Bugs & Issues
KeyNotFoundException on CF 3.5
Page:1/1 

  Print all messages in this thread  
Poster Message
patramadass
User



Location:
Port Elizabeth, South Africa
Joined on:
05-Feb-2008 21:51:49
Posted:
35 posts
# Posted on: 09-Mar-2010 09:55:12.  
Hey there,

I am using...

v2.6
Release Date - 25/02/2010

...on a Compact Framework project targetting CF .NET 3.5 and using the Adapter templates with SQL Server CE 3.5 SP1 database. We have an inheritance hierarchy where Customer inherits from Address as follows..

CREATE TABLE [dbo].[Address](
    [AddressId] [uniqueidentifier] ROWGUIDCOL NOT NULL,
    [CountryId] [uniqueidentifier] NOT NULL,
    [AddressLine1] [varchar](20) NOT NULL,
    [AddressLine2] [varchar](20) NOT NULL,
    [City] [varchar](20) NOT NULL,
    [State] [varchar](20) NOT NULL,
    [PostalCode] [varchar](20) NOT NULL,
    [SalesCode] [varchar](10) NULL,
CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED
(
    [AddressId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Address] WITH CHECK ADD CONSTRAINT [FK_Address_Country] FOREIGN KEY([CountryId])
REFERENCES [dbo].[Country] ([CountryId])
GO

ALTER TABLE [dbo].[Address] CHECK CONSTRAINT [FK_Address_Country]
GO

ALTER TABLE [dbo].[Address] ADD CONSTRAINT [DF_Address_AddressId] DEFAULT (newid()) FOR [AddressId]
GO

...and...

CREATE TABLE [dbo].[Customer](
    [CustomerId] [uniqueidentifier] ROWGUIDCOL NOT NULL,
    [CustomerCategoryId] [uniqueidentifier] NULL,
    [Code] [varchar](50) NULL,
    [Name] [varchar](20) NOT NULL,
    [ContactNumber] [varchar](50) NOT NULL,
    [isBlocked] [bit] NOT NULL,
    [isCashCustomer] [bit] NOT NULL,
    [AccountType] [varchar](10) NULL,
    [VATNumber] [varchar](20) NULL,
    [FaxNumber] [varchar](50) NULL,
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
(
    [CustomerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [IX_Customer_Name] UNIQUE NONCLUSTERED
(
    [Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_Address] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Address] ([AddressId])
GO

ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_Address]
GO

ALTER TABLE [dbo].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_CustomerCategory] FOREIGN KEY([CustomerCategoryId])
REFERENCES [dbo].[CustomerCategory] ([CustomerCategoryId])
GO

ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_CustomerCategory]
GO

ALTER TABLE [dbo].[Customer] ADD CONSTRAINT [DF_Customer_isBlocked] DEFAULT ((0)) FOR [isBlocked]
GO

ALTER TABLE [dbo].[Customer] ADD CONSTRAINT [DF_Customer_isCashCustomer] DEFAULT ((1)) FOR [isCashCustomer]
GO

It's actually part of an occasionally connected application and there is a web front end for which we are using v3.0 beta with the same design. It seems fine on v3.0 beta, but when trying to Save a Customer on the CF application we are getting a KeyNotFoundException, seemingly similar to the issues mentioned here...

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=10571&HighLight=1

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=14496&HighLight=1

...but with CF we can't use the app.config and the SetSqlServerCompatibilityLevel. Is there something else that could be causing this that is specific to CF? We have used LLBLGen Pro v2.6 with a few CF projects, but this is seemingly the first subtype scenario.

The StackTrace is...

" at System.ThrowHelper.ThrowKeyNotFoundException()\r\n at System.Collections.Generic.Dictionary`2.get_Item(IEntityFieldCore key)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateInsertDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateInsertDQ(IEntity2 entityToSave, IFieldPersistenceInfo[] persistenceInfoObjects)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateQueryForEntityToSave(Boolean insertActions, EntityBase2 entityToSave, IPredicateExpression updateRestriction, InheritanceHierarchyType typeOfHierarchy, IFieldPersistenceInfo[] persistenceInfoObjects)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave)\r\n at ...SaveEntity(IEntity2 entity, Boolean recursive)\r\n at ..."

Thanks in advance,

-Pat Ramadass
  Top
patramadass
User



Location:
Port Elizabeth, South Africa
Joined on:
05-Feb-2008 21:51:49
Posted:
35 posts
# Posted on: 09-Mar-2010 10:17:43.  
Hi there again,

It's also worth mentioning that the table creation scripts posted are those from the main SQL Server 2008 database with which the devices are synchronising (via the Sync Framework) and as per...

http://stackoverflow.com/questions/1818560/ms-sync-framework-table-schema-not-copied-to-local-db

...the NewId() setting is not carried across when the local database cache (the .sdf) gets created, but even when we set it specifically on the table within the .sdf this error still occurs.

Thanks,

-Pat Ramadass


  Top
Walaa
Support Team



Location:
Egypt
Joined on:
21-Aug-2005 16:03:48
Posted:
9817 posts
# Posted on: 09-Mar-2010 11:44:10.  
What about using NewSequentialId() instead of NewId() would it make any difference?
LLBLGen Training
http://www.linkedin.com/in/walaa
 
Top
patramadass
User



Location:
Port Elizabeth, South Africa
Joined on:
05-Feb-2008 21:51:49
Posted:
35 posts
# Posted on: 09-Mar-2010 12:29:29.  
Hey there again,

NewSequentialId() is not supported in SQL Server CE 3.5 SP1 (version 3.5.5692.0), but no I don't think it would make any difference sadly.

-Pat Ramadass


  Top
patramadass
User



Location:
Port Elizabeth, South Africa
Joined on:
05-Feb-2008 21:51:49
Posted:
35 posts
# Posted on: 09-Mar-2010 12:50:31.  
Hi there again,

Further to this it seems like none of the default values on fields are being honoured for some reason. If I add the following code...

            if (CustomerEntity.IsNew)
            {
                CustomerEntity.IsBlocked = false;
                CustomerEntity.IsCashCustomer = true;

                Guid guid = Guid.NewGuid();
                CustomerEntity.AddressId = guid;
                CustomerEntity.CustomerId = guid;
            }

...then the entity saves, but both IsBlocked and IsCashCustomer have default values, yet if I don't set them I am getting...

{"An exception was caught during the execution of an action query: The column cannot contain null values. [ Column name = isBlocked,Table name = Customer ]. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."}

...but the default values are present when viewing the Database Schema in Visual Studio and also work when adding to the table manually via Visual Studio.

Thanks,

-Pat Ramadass
  Top
Walaa
Support Team



Location:
Egypt
Joined on:
21-Aug-2005 16:03:48
Posted:
9817 posts
# Posted on: 09-Mar-2010 13:01:25.  
Quote:
but with CF we can't use the app.config and the SetSqlServerCompatibilityLevel.

Use the DataAccessAdapter.SetSqlServerCompatibilityLevel() static method.
Quote:
NewSequentialId() is not supported in SQL Server CE 3.5 SP1 (version 3.5.5692.0),

I didn't know that, are you sure about this, do you have a reference for it.

Quote:
Further to this it seems like none of the default values on fields are being honoured for some reason. If I add the following code...

            if (CustomerEntity.IsNew)
            {
                CustomerEntity.IsBlocked = false;
                CustomerEntity.IsCashCustomer = true;

                Guid guid = Guid.NewGuid();
                CustomerEntity.AddressId = guid;
                CustomerEntity.CustomerId = guid;
            }

...then the entity saves, but both IsBlocked and IsCashCustomer have default values, yet if I don't set them I am getting...

{"An exception was caught during the execution of an action query: The column cannot contain null values. [ Column name = isBlocked,Table name = Customer ]. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."}

This seems like a database error, and so the default values are not honored by the database.
Are you sure you are targeting the correct database schema?


LLBLGen Training
http://www.linkedin.com/in/walaa
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.