The object name 'voa_keygen' is invalid ???

17 posts, 0 answers
  1. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 04 Dec 2014 Link to this post

    Hello, Admin.
    Very strange, don't know why, occasionally will throw an exception:
    "The object name 'voa_keygen' is invalid."
    All the tables have a primary key.
    It looks like the intermittent seizures, be rather baffling.....
  2. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 04 Dec 2014 Link to this post

    I think there is a problem here.
    After adding this override method
    protected override void OnDatabaseOpen(Telerik.OpenAccess.BackendConfiguration backendConfiguration, Telerik.OpenAccess.Metadata.MetadataContainer currentMetadataContainer, Telerik.OpenAccess.Metadata.MetadataContainer aggregatedMetadataContainer)
    {
        currentMetadataContainer.UniqueIdGenerator.CreateTable = true;
    }
    As long as the call to Context, all wrong...
    Because after the delete of this method, no exception is throw.
  3. DevCraft banner
  4. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 09 Dec 2014 Link to this post

    Hi Allen,

    The cause for this error lies in the fact that Telerik Data Access needs to associate the persistent classes with primary keys, and by design the persistent classes mapped to views do not have primary keys. To resolve the situation you can apply either one of the solutions suggested in this documentation article.

    Do let us know if you need further information.


    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  5. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 10 Dec 2014 in reply to Doroteya Link to this post

    Hi,Doroteya.
    Each table has a primary key..
    Thanks.
  6. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 11 Dec 2014 Link to this post

    Hi Allen,

    I am sorry you are still experiencing issues.

    The error appears only when the model on your side contains a persistent class without a primary key property. Usually, such a scenario occurs, when the model contains views (in addition to the tables). Both the tables and the views from the database are mapped to persistent classes from Data Access perspective, but since the views do not have primary keys in the database, their corresponding persistent classes have no primary key properties.

    For better understanding of the situation, you can take a look of the view-example.png screenshot. Note that TableId in MyTable is marked as a primary key, while TableId in MyView is not. For your convenience and for an easier way to find such cases, our validation framework will display both an error and a warning in Error List.

    In this connection, I strongly recommend to you to review the content of Error List for such errors and warnings.

    To nominate a given property for a primary key, you need to select it, and to set the Identity property to True, as demonstrated on view-primary-key.png.

    Once you do that, you need to save (Ctrl + S) the model before running the application for a test.

    I hope this helps. Let us know, if you are still experiencing the error.



    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  7. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 11 Dec 2014 in reply to Doroteya Link to this post

    Hi,Doroteya.
    First,sincerely thank you for your reply...
    You say I'm know all..
    The crux of the matter is not here.
    Because this code: currentMetadataContainer.UniqueIdGenerator.CreateTable = true;
    Now I have solved, is that another admin help me solved!
    In OpenAccessContext derived class, add a method:
    public void UpdateSchema()
    {
        var handler = this.GetSchemaHandler();
        string script = null;
        try
        {
            script = handler.CreateUpdateDDLScript(null);
        }
        catch
        {
            bool throwException = false;
            try
            {
                handler.CreateDatabase();
                script = handler.CreateDDLScript();
            }
            catch
            {
                throwException = true;
            }
            if (throwException)
                throw;
        }
     
        if (string.IsNullOrEmpty(script) == false)
        {
            handler.ExecuteDDLScript(script);
        }
    }
    And in the Global.asax.cs's Application_Start() call UpdateSchema().

  8. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 16 Dec 2014 Link to this post

    Hello Allan,

    Thank you for getting back to us. I am glad that currently things are working on your side.

    Let me confirm that, indeed an update of the database schema is necessary in order to consume the sequential guids generated by Telerik Data Access. During this update, the voa_keygen table will be created in the database, so that it is always possible for Data Access to know the last generated value.

    Let us know, if you need further information.


    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  9. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 17 Dec 2014 in reply to Doroteya Link to this post

    New problems coming.
    From this picture, you can clearly see the three view fields are not all primary key fields.
    Therefore, it is not possible to set a primary key.
    So, what should I do?
    Otherwise an exception will be thrown.
  10. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 17 Dec 2014 Link to this post

    Cannot upload pictures in the Forum, really too much trouble ...Pictures are here.
  11. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 18 Dec 2014 Link to this post

    Hello Allen,

    In such situations, the best approach is to make a combination of the existing properties, that will uniquely identify each object returned by the view. For example: you can take a look at the attached screenshot (views-with-multiple-primary-key-properties.png). Note that there are cases when you may need to mark all the properties as primary keys and this is completely fine with Data Access, as long as the combination provides unique identification of the returned objects.

    I hope this helps. Let us know how are the things on your side. 

    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  12. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 18 Dec 2014 in reply to Doroteya Link to this post

    Hello Doroteya.
    It really won't have any problems?
    After you set the primary key, duplicate values will be how to deal with by ORM? such as name fields.
    I guess I have to do a little test.
    In any case, really thanks for your help.
  13. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 19 Dec 2014 Link to this post

    Hi Allen,

    Indeed, when you work with views such a manual marking of a combination of properties is fine with Data Access. The idea is Data Access to be able to distinguish between the different objects returned by the view (and this fictitious selection helps exactly for that) . 

    In case you have something specific are a consideration in mind, let me know and we will provide you with details.

    I hope this helps.



    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  14. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 19 Dec 2014 in reply to Doroteya Link to this post

    Hello, Doroteya.
    Test result is TDA ORM filter duplicates, this is not what I want.
     I do not wish to filter out these duplicate values.
    Does I have to use the most stupid ADO API?
    Thanks
  15. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 19 Dec 2014 in reply to Doroteya Link to this post

    Hello, Doroteya.
    Test results is a little funny.
    var query = ContextFactory.GetContextPerRequest().V_TestView_Users;
    var test_user = query.Where(t => SqlMethods.Like(t.Name, "Chadwick Potter")).ToArray();
    //Test Result: 10 records
    //Return result:
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
    //Chadwick Potter
     
    var test_user2 = query.Where(t => t.Name == "Chadwick Potter").ToArray();
    //Test Result: Only one record
    //Return result:
    //Chadwick Potter
    I don't get it...
  16. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 22 Dec 2014 Link to this post

    Hi Allen,

    The behaviour you observe is expected. Data Access will filter duplicates, when the chosen combination of primary key properties does not provide unique distinction between the returned objects. In you case, it is possible to retrieve everything with the help of a little modification in the view. This modification includes adding a row number for each row in the view result and nominating the row number column as a primary key property in the model. The final result will look in your model as demonstrated in the attached screenshot (row-number-added.png). The implementation steps are as follows:

    1. Open the view for edit (if you are using MS SQL Server and Management Studio, simply right-click on the name of the view in Object Explorer and select Design).
    2. Using the row_number() function, add a new column in the shape of the view
    3. Save the view (Management Studio usually complaints that it cannot display the performed change. You can safely disregard the warnings and click the OK buttons).
    4. Update the view with the changes using the Update From Database wizard. The steps are described here in details.
    5. In the designer, set the newly added row property as a primary key property for the view.
    6. Save the model.

    At this point Data Access will return every row provided by the view.

    I hope this helps. Let us know if you need further assistance.


    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  17. Allen
    Allen avatar
    42 posts
    Member since:
    Nov 2014

    Posted 26 Dec 2014 in reply to Doroteya Link to this post

    Hi, Doroteya.
    I have thought about this method, but it is very easy to cause a full table scan.
    Thanks.

    Merry Christmas...
    ^_^
  18. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 29 Dec 2014 Link to this post

    Hi,

    If you have selected to have Name as primary key the difference in behavior is expected.
    Telerik Data Access will take a special shortcut if you are filtering by the primary key. In that case you will get a single result even if there are many more records that are matching your filter criteria.
    To get more than one row in the results you may use the following code:
    var query = ContextFactory.GetContextPerRequest().V_TestView_Users;
    var test_user = query.Where(t => t.Name.StartsWith("Chadwick Potter")).ToArray();


    Regards,
    Viktor Zhivkov
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top
DevCraft banner