This is a migrated thread and some comments may be shown as answers.

Latest OpenAccess release selecting non-existent column

3 Answers 124 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 28 Jun 2012, 12:03 AM
Here is the line of code I get the exception on:

User user = voContext.Users.Where(u => u.EmailAddress == emailAddress).FirstOrDefault();

Here is the exception I get:

Error executing query: Telerik.OpenAccess.RT.sql.SQLException: Invalid column name 'UserId'.
Statement(s) could not be prepared.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()
   at OpenAccessRuntime.Relational.fetch.FetchResultImp.Execute()
SQL:
SELECT  TOP(??T) a.[AssetId] AS COL1, a.[EmailAddress] AS COL2, a.[FirstName] AS COL3, a.[LastName] AS COL4, a.[OrganizationId] AS COL5, a.[OrganizationId] AS COL6, a.[UserId] AS COL7, b.[AssetId] AS COL8, b.[Class] AS COL9, b.[CreationDate] AS COL10, b.[Deleted] AS COL11, b.[DeletionDate] AS COL12, b.[AssetId] AS COL13 FROM [Users] a JOIN [Assets] AS b ON (a.[AssetId] = b.[AssetId]) WHERE a.[EmailAddress] = ?                                        Telerik.OpenAccess.RT.sql.SQLException: Invalid column name 'UserId'.
Statement(s) could not be prepared.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()
   at OpenAccessRuntime.Relational.fetch.FetchResultImp.Execute()

Here is a link to a zip file of the RLinq file and associated generated files.

https://s3.amazonaws.com/SolidCloud-software/SolidCloud/Model20120627.zip

That column exists in a related table, but not the users table. Everything worked fine in the previous release. Any suggestions would be appreciated.

3 Answers, 1 is accepted

Sort by
0
Viktor Zhivkov
Telerik team
answered on 29 Jun 2012, 03:40 PM
Hello Chris,

As far as I can see in your data model the User entity has no identity key defined. OpenAccess requires all entities to have identities.
Also looking at the UserPermissions entity there is UserId which is Guid and is used as a foreign key for the relation between User and UserPermissions.
If you want a working and semantically correct data model please add identity key to User entity and elsewhere it is missing. Then update your database schema using the Update Database From Model command.

If you need any further assistance, please do not hesitate to contact us.

Greetings,
Viktor Zhivkov
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Chris
Top achievements
Rank 1
answered on 29 Jun 2012, 03:55 PM
The thing is, I generated this model from the database and the database has all the appropriate keys set. However, I've adjusted the model to do some vertical inheritance which necessitates removing keys from child entities and letting the base entity hold the key. Users is one of those tables I've removed the key on since it inherits Assets. This same model works fine in the previous release aside from one-to-one relationships. 
0
Zoran
Telerik team
answered on 04 Jul 2012, 01:48 PM
Hello Chris,

 The reason for this behavior was that the 1:1 association between User and PendingConfirmation was not fully defined. The foreign key (UserId) was defined as the foreign key of the association, however there was missing information that AssertId is the key used from the User side of the association. This is something that we should improve, so that we detect the primary key column as part of the association. When that information is missing, OpenAccess tries to find a column with the same name as the column from the opposite side of the association.

However, I did select the AssertId column as the column used from the User side of the association with the Association Editor and it seems on my side that this problem is now fixed. I am sending you the fixed model so you can try it on your side.

Kind regards,
Zoran
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
Data Access Free Edition
Asked by
Chris
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
Chris
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or