Binding to gridView : object context not available

7 posts, 0 answers
  1. Krasimir
    Krasimir avatar
    6 posts
    Member since:
    May 2009

    Posted 15 Dec 2009 Link to this post

    I am new to OpenAccess (and to ORM for that matter) and I'm following through the Falafel's courseware. I stumbled on CRUD operations, especially adding a row to the gridView - it gives me " OpenAccessException :No object context  available". Loading and updating existing rows are just fine. Actually, the same happens with the sample code the guys from Falafel give as an example. I am aware that the new object instantiated must be added to the scope (and if I do so, manually , it works fine) , but isn't ObjectView supposed to do that automatically. Bear with me, I'm working with OpenAccess for a couple of days only, so probably I'm missing something obvious. Please give me an advice!
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 16 Dec 2009 Link to this post

    Hi Krasimir,

     First, do I correctly understand that you are using the RadGridView for WinForms?

    Also, I tried reproducing your case using the latest versions of both OpenAccess and RadControls for WinForms, but unfortunately I was not able to reproduce this exception that you mention.

    Can you share with us more details about your case? What versions of OpenAccess and RadControls for WinForms are you using? What are the exact steps that you take in order to reproduce the exception? Also, can you point us to the exact place in the Falafel course-ware or sample project that you are referring to so that we can review it and fix it if necessary?

    Regards,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Krasimir
    Krasimir avatar
    6 posts
    Member since:
    May 2009

    Posted 17 Dec 2009 Link to this post

    Hi, Jordan!
         Thank you for the reply. In my case I use the Microsoft's DataGridView and SqlServer compact 3.5 as backend, but the same thing is with the Falafel's project which use RadGridView and SqlServer Express.  It's in the "Using OpenAccess in Applications" chapter and the project is :Projects\<CS|
    VB>\3_OpenAccessInApplications\3_OpenAccessInApplications.sln, project
    "2B_MyWinFormCrud" . The telerik winform controls is 2009 Q1 I think, but the OpenAccessExpress is 2009 Q3 (the last version). I'll send you an image with the exception. I didn't change anything in Falafel's project except the connection string and I followed the steps as they were written. As I said, updating data is Ok, so I have connection to the database. The problem is when I add new row, enter some values and try to leave the row. Validation fails for some reason...
    By the way, when I followed the example for WebService in their courseware they used ObjectContainer and custom bindingList. Everything worked fine, so maybe I should manually add the object to the scope in some event handler?

  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 18 Dec 2009 Link to this post

    Hi Krasimir,

    I was able to successfully reproduce the issue using the Falafel example the you pointed to.
    It happens because in the cbCategories_SelectedIndexChanged method the products for the selected category are set through ovProduct.DataSource, which is incorrect.
    The correct way is to use opProduct.ObjectSource like in the snippet bellow:
    opProduct.ObjectSource = from product in _scope.Extent<Product>()
                                       where product.CategoryID == selectValue
                                       select product;
    You must have in mind that although this will resolve the exception the new products will not have a category assigned, and you will probably want to assign a category to the newly created products.

    I hope this helps.

    Regards,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Krasimir
    Krasimir avatar
    6 posts
    Member since:
    May 2009

    Posted 18 Dec 2009 Link to this post

    Hi, Jordan!

    Thank you! Yes, this solves the exception, though it is not solving the main problem - saving the added row to the database. I understand that assigning category is necessary for querying later, but is it really needed for saving? Shortly, I'm still not able to save the new data to the database. Nothing happens. The transaction is not dirty which means the new object is not automatically added to the scope. Could you point me the best way to save the data? Probably, when I create new form with some text boxes, instantiate a new Product object, populate its properties, and add it to the scope it will be OK.  It will be nice though to that directly in the grid. What is best practice in that case?
  7. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 21 Dec 2009 Link to this post

    Hi Krasimir,

     Yes, you are right, that helped us spot another issue in the mentioned example. The code for saving a record in the database should be replaced with the following:

    opProduct.SaveAll()

    We are sorry for the inconveniences caused. At the moment we are working on  polishing the Falafel examples as some of them are out of date having in mind the changes our product went through after the Falafel guide was made.

    Kind regards,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Krasimir
    Krasimir avatar
    6 posts
    Member since:
    May 2009

    Posted 21 Dec 2009 Link to this post

    Thank you, guys! It's OK, now!

    Happy holidays and keep on the good job you're doing!


Back to Top
DevCraft banner