Using ORM First Time

22 posts, 1 answers
  1. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 19 May 2011 Link to this post

    My last project i used Entity Framework 4.0 to create my data model and then RIA services to link to my silverlight project.
    I would like to now use all the telerik tools as there really look like they can increase the speed of the development.
    So i have started with creating a model using OpenAccess, i chose create data model from the menu.
    So far so good. Created some domain objects, used default mapping for tables, created a script for my database executed it.
    All fine.
    Next step, i am trying to create a domain service. The Open Access RIA wizard pops up i chose my DataContext.
    And there is nothing in it.
    I just see a grey box, No list of entities to select from or anything.

    What am i doing wrong?
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 20 May 2011 Link to this post

    Hello Andrew,

     That is actually a limitation of the RIA wizard itself. The default mapped tables actually does not live in the model and as such they cannot be displayed in the ria wizard. This problem has been fixed in our new version of the RIA wizard that will be shipped with our next service pack.
    What you can do is add the domain service without selecting any endpoints. This will create a class that will inherit from our domain service implementation. You can than edit the tt template to add the classes you need to generate. Here is an example:

    string fileName = "DomainService1";
    string contextTypeName = "EntitiesModel";
    string contextNamespaceName = "ConsoleApplication111";
    string queriableTypesInput = "Category;Product";
    string queriableClassNamesInput = "Categories;Products";
    string[] queriableTypes = null;
    string[] queriableClassNames = null;
    string editableEndPoints = "Category";
    where queriableTypesInput are the types you want to generate, queriableClassNamesInput are the endpoints. Please note that the type names and the endpoint names should be in the same order. Also if you want your classes to be editable you will have to add their type in the editableEndPoints string.
    The above example will generate endpoints for Category and Products where only the Category endpoint will be editable.



    All the best,
    Petar
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  3. DevCraft banner
  4. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 23 May 2011 Link to this post

    I am not sure i understand what to do here. Are you saying I should first add the domain service and then add the code you showed me? What about the generated.cs file? What do I need to add there?

    This might be a little bit beyond me; perhaps I should go back to Entity Framework.

    :(
  5. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 25 May 2011 Link to this post

    Having removed the model and recreated it. this time from the database, exactly the same model.
    I am able to now create the domain service.
    I don't understand why this works.
    Is this indented?
    What will happen if i create an additional entity?
    This is very confusing, what is the difference between the two models?
  6. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 25 May 2011 Link to this post

    Hello Andrew,

    The reason you were not able to work with the RIA wizard on the first place were the default mapped tables. Those tables were replaced by the ones on your server once you reverse mapped your model. The problem with the default mapped tables is that they are not real tables. They are fictitious tables showing to the user what the table would look like should he decide to create it. However until they are created they are not really there and thus the wizard is not able to use them.
    My instructions from my previous post hinted that you should add the domain service even though you are not able to see the entities and then alter the tt file as per the instructions stated there.
    Please do let me know if you have any further difficulties.

    Regards,
    Petar
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  7. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 28 May 2011 Link to this post

    Hi Petar,

    I have tried what you described. It generated my genrated.cs file. All looks good.
    However i get an error when trying to complie the solution.

    "The entity 'Organisation' in DomainService 'cintDomainService' does not have a key defined. Entities exposed by DomainService operations must have at least one public property marked with the KeyAttribute. "

    Any ideas why that happened?
  8. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 28 May 2011 Link to this post

    Hello Andrew,

     The RIA data services use a naming convention to determine the primary key of a class. If for some reason the primary key is not discoverable you can encounter this error. The solution for this is to mark the primary key of the failing class with the [Key] attribute. Please note that this is rather RIA services limitation rather than OpenAccess one.

    Greetings,
    Petar
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  9. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 28 May 2011 Link to this post

    Having done a test, this only happens when i create an empty EntityModel with OpenAccess, in the same project it does NOT happen when i create teh model from database or use Entity Model 4.0.

    Do i understand you cerrectly that i need an atribute on the class in the organisation.generated.cs file?
    Will this not be removed every time the EntityModel is changed?

    Should not this be some sort of property one can set on the model?
  10. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 28 May 2011 Link to this post

    I have added the following to the generated.cs file:

    using

     

     

    System.ComponentModel.DataAnnotations;

     


    private

     

     

    int _id;

     

     

    [

     

    Column()]

     

     

    [

     

    Storage("_id")]

     

     

    [

     

    Key]

     

     

     

     

    public virtual int Id

     

     

    {

     

     

     

    get

     

    {

     

     

    return this._id;

     

     

    }

     

     

     

    set

     

    {

     

     

    this._id = value;

     

     

    }

     

    }

    I hope that is what you ment.

    It compiles now, but i get an error when running the project, the error: " An error occured while loading data through the 'GetOrganisationsQuery' query."

  11. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 31 May 2011 Link to this post

    I have added a partial class to my project so that the [Key] atribute does not get removed if i change the model.
    I am still getting an unhandled exception.
    This only happens when i create the model in the project then create the database from the model.
    I have created another project (for testing) and had the wizard create the model from teh database, this way i don't get an error.
    I also do not get an error when doing the exact same with Entity Model Wizard.
    So it is a problem with Open Access.
  12. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 31 May 2011 Link to this post

    Nothing? Really?
    Am i the first person to encounter this error?
    That does not seem likely.

  13. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 01 Jun 2011 Link to this post

    Hello Andrew,

     Can you please check what is the key generator in the case when you generate your database from your model? Is it possible that you are relying on the internal primary key implementation from OpenAccess?

    Kind regards,
    Petar
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  14. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 01 Jun 2011 Link to this post

    What do you mean by key generator?
    Are you refering to the indentiy mechanism in the class?
    You need to be a little bit more specific.
  15. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 02 Jun 2011 Link to this post

    If you are referring to the identity mechanism, i have it set to DatabaseServerCalculated so that my database id is set to both key and identity.

    Also, i am not sure if this really matters here, as i am not creating any actual records yet. I am far from that.
    This error occurs on the "get" query.

  16. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 02 Jun 2011 Link to this post

    I have now found the inner exception for hit error:

    "Type is enhanced and registered, but not available from the database class meta data. This can be caused by wrong connection id or configuration."

    I see from your forum that this happens when you have more than one data model in the project.
    I only have one so that is not an issue here.

    I would really appreciate your prompt response. I have now been trying OpenAccess for two weeks and am nowhere close to even making a small sample app that will work.

    Thanks

  17. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 06 Jun 2011 Link to this post

    I have now found a solution for the problem.
    Unfortunately that is not a solution that can be implemented.
    It is a problem with your software. When creating the model it does not generate the object file correctly.
    If i add the following two lines to the generated file it will work:

     

     

    [

     

    Table("product")]

     

     

     

     

     

    and

     

     

    [

     

     

    Column("product_id", OpenAccessType = OpenAccessType.Int32, IsBackendCalculated = true, IsPrimaryKey = true, SqlType = "int")]

     

     

     

     

     


    The problem is of course that i cannot simply type that in there as it will disappear when it is regenerated.

    What do you propose I do to solve this error?

  18. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 07 Jun 2011 Link to this post

    Hello Andrew,

     Are the entities you needed to add the table and column attributes default mapped? Currently our attribute mapping is lacking the functionality to handle default mapped entities. The easiest solution would be to switch to xml mapping as there everything is fully supported. If this is not an option for you I will advice you to add metadata classes(buddy classes) and define your attributes there. This way the will not be overwritten on each code generation.

    All the best,
    Petar
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  19. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 10 Jun 2011 Link to this post

    I tried the matadata classes, but even when putting the

    Column("product_id", OpenAccessType = OpenAccessType.Int32, IsBackendCalculated = true, IsPrimaryKey = true, SqlType = "int")]
    It would not work. i had the same error.

    Now i am trying to use the xml mapping, but i am not sure how to use it.
    Is it different?
    I changed it and recreated my DomainService.

    But now get an error saying:
    Unable to load the metadata for assembly...

    Is there soemthign else one does when usign this kind of mapping?

    Do you have an example on how to do this?

  20. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 13 Jun 2011 Link to this post

    Ok, fixed that.
    It appears that when trying to convert to xml the model just does not work.
    I scrapped the project and tried it in a new test one. It works with XML.

    I have one question.

    What are the advantages and disadvantages of the two mapping types?

    Apart from the obvious one works the other does not of course.

    My question applies to the point when you have fixed the issue in a new release.

    Thanks.

  21. Answer
    PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 15 Jun 2011 Link to this post

    Hi Andrew,

     The attribute mapping is somewhat more obvious and easy to see and understand than the xml mapping. In the end they should be the same (though currently our xml mapping is better supported than the attribute mapping).
    All the information you are able to see in the attributes mapping can be seen in the xml as well.

    Kind regards,
    Petar
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  22. Michael
    Michael avatar
    19 posts
    Member since:
    Oct 2011

    Posted 09 Nov 2012 Link to this post

    I feel your pain Andrew. I so want to use this product but am finding new reasons not to by the moment. It's one bug or "limitation" after another. Needing a separate project for each model is ridiculous and I need separate models because of other "limitations". It getting really out of hand.
  23. Ivailo
    Admin
    Ivailo avatar
    318 posts

    Posted 13 Nov 2012 Link to this post

    Hi,

    I just want to note in this thread the progress that was made on the topics mentioned:

    - We have been improving the Attributes mapping a lot during the last 18 months and in Q3 2012 you will find it much more mature and useful
    - Using more than one model is possible in a single project, although not out of the box, as we assume in the majority of cases only one context is used for data access. You can even define two models and still access your database using only one context, as specified here. Furthermore, in the next release we are planning to deliver support for many diagrams based on one model for further flexibility and manageability of larger models.
    - There are many other usability improvements shipped with the latest release

    Of course, there is still a lot we can improve and we will most certainly continue working in that direction for the future releases of OpenAccess ORM, so do not hesitate to provide any feedback you have.

    Kind regards,
    Ivailo
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Back to Top
DevCraft banner