Latest OpenAccess release selecting non-existent column

4 posts, 0 answers
  1. Chris
    Chris avatar
    40 posts
    Member since:
    Feb 2009

    Posted 27 Jun 2012 Link to this post

    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.

  2. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 29 Jun 2012 Link to this post

    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!
  3. DevCraft banner
  4. Chris
    Chris avatar
    40 posts
    Member since:
    Feb 2009

    Posted 29 Jun 2012 Link to this post

    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. 
  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 04 Jul 2012 Link to this post

    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!
Back to Top