NHinernate to OpenAcess

10 posts, 0 answers
  1. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 15 Apr 2011 Link to this post

    I need to change from NHibernate to Open Acess because of customer requirement and I am little confused with use of Open Acess mainly because is new and I use NH for a long time already. I see SDK samples (http://www.telerik.com/account/your-products/trial-product-versions/trial-single-download.aspx?pmvid=0&pid=638) and download ORM documentation. For me its easy to use one sample with two implementations to try ti understand the differences.

    For example I have two classes: Product (Id, Name and IdProductType) and ProductType (Id and Name). All fields are string and the table ProductType is already populated.

    In NHibernate the Product mapping shows Id, Name and ProductType as object and using OA Wizard I have ProductType twice, one as property string IdProductType and other in Navigation as ProductType. 

    1) In NH I only need to set the property ProductType and the FK will be filled automaticaly. If I do the same in OA I receive a duplicate key erro in table ProductType because OA execute a insert. So I change the property ProductType to Persistent Read Only. I think wrong an this put the Property with read only instead of to avoid insert. OK, it´s my mistake. In my tests OA force me to set IdProductType property, but for me appears redundant. Can I to implement the same way in NH ? I found the documentation for the properties of tables and fields very weak with no explanation. For example IsDependent, the help tell me "Specifies that this navigation property is dependent". There is no help is this text. I am see the wrong documentation (Telerik_OpenAccess_ORM_2011_1_316_documentation.zip) ?

    2) In NH I set every PK with uuid.hex generator wich creates a guid. I do this to avoid problems with different databases. I try to use GUID in OA but its force me to change the type of me properties to GUID. Can I use a custom generator in OA ?

    3) I used Add Domain Model option to generate my mapping class. I put the Entity Diagram in my Entitie project and logically every project im my solution use them. Why OA forces me tu reference OpenAcess.dll in every project ? Just to remember, my project its already finished, but using NH.

    I'm using Visual Studio 2008 with .NET 3.5, ORM version 2011.1.316.10.





  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 18 Apr 2011 Link to this post

    Hi Marcelo,

    1.  OpenAccess used to perform mapping in the same way in its early versions, however after some customer requests we introduced this as a feature to be able to control the FK value even if you do not have the object in memory but only its identity. However it should be possible to control this value either by the object reference or by the simple FK filed. If it is not possible to do it both ways - it means there is a bug somewhere which we will have to address. If you are in such a situacion we will be glad if you could send us more information on how to reproduce it on our side and we will make sure it is fixed for the next release.
    2. At the moment it is not possible to use custom generator with OpenAccess but it is possible to use Guid identity very easily. You just have to make the identity field of type GUID and set Guid as a key generator for that entity. OpenAccess will internally take care of assigning new Guids for the objects when you create the during runtime.
    3. It is not obligatory to have references to Telerik.OpenAccess.dll in each project - only in those that actually use OpenAccess. That means the projects that have .rlinq files as well as those that have some business logic using the OpenAccess generated objects.
    Best wishes,
    Zoran
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 18 Apr 2011 Link to this post

    Thaks for your reply

    1 - What I am try to do its simple (using the sample of my first post):

    ProductType productType = Context.GetObjectByKey<ProductType>("9f7e76c407ce4bbe92a6e35aaeac3fb3"); 
    Product product = new Product(); 
    product.Id = "000000000000000000000000000001";
    product.Name = "New Product";
    product.ProductType = productType;
    Context.Add(product);
    Context.SaveChanges();

     

    If I try this I receive a error because FK for ProductType cannot be null and I not explicit set IdProductType field only set ProductType. I thought it was the same thing. If I change the code like I show below its work.

     

     

    ProductType productType = Context.GetObjectByKey<ProductType>("9f7e76c407ce4bbe92a6e35aaeac3fb3");
    Product product = new Product();
    product.Id = "000000000000000000000000000001";
    product.Name = "New Product";
    product.IdProductType = productType.Id;
    Context.Add(product);
    Context.SaveChanges();

    2 - Yes I see this feature, but I am converting a project to use ORM, so I will try to find another way to do this, probably in insert method of my DAL.

    3 - I think you are right, but not what is happening. My Entities project has a rlinq file and several files classname.generated.cs with ORM OpenAccess.TableAttributes and obvious a OpenAcess reference. I don´t use Wizard to generated others objects and my solution has others projects : Business, DataAccess, WCF Service, WCF Client and a separetad project only with ASPX. DataAccess need OpenAcess refence, but the others projects I think don´t. Alls project has a reference to Entities project and if I don´t to put the error below shows when a compile de solution:

    The type 'Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable' is defined in an assembly that is not referenced. You must add a reference to assembly 'Telerik.OpenAccess, Version=2011.1.316.10, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342'

  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 20 Apr 2011 Link to this post

    Hello Marcelo,
    1. We tried to use code similar with yours, but inserting a new object worked both ways - assigning the foreign key directly or assigning it through a related object. I guess you have some edge case which we can not reproduce yet, so I believe that it would be the best if you could send us a sample application where you observe this problem so we can debug it and fix the problem if such is located. In order to send us a project you should open a support thread as it is not possible to attach a project in a forum.
        3.   We were not able to reproduce this problem either We made a sample Class Library application and               added a reference to it from a web application. The web application did not required                                               Telerik.OpenAccess.dll in order to compile. I guess we could look at both problems with the same                     approach as I mentioned above - sending us an application is the most reliable form of solving these               problems.

    Best wishes,
    Zoran
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 25 Apr 2011 Link to this post

    Sorry for delay.

    I open 417624 ticket with a attached solution wich demostrate the errors. I believe its not a Telerik error, is probably related to my little experience with telerik
  7. Myth
    Myth avatar
    54 posts
    Member since:
    Jan 2010

    Posted 08 Oct 2013 Link to this post

    Sorry for picking up this thread again but i have the same issue as nr 3:

    I have one project which contains my Domain objects my context and fluentMappingMetaData. I expose the context using a custom interface and unity to other modules. So normally my other modules should not know about telerik openaccess whatsoever. Yet when compiling them i get the following message:

    'The type 'Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable' is defined in an assembly that is not referenced. You must add a reference to assembly 'Telerik.OpenAccess, Version=2013.2.702.1, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342'.'

    This kind of breaks the point of having a modular application and Unity for abstraction.

    Kind regards,
    Stijn
  8. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 09 Oct 2013 Link to this post

    Hello Stijn,

    The reason for this build error is that all of the entities used in your model inherit from the Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable interface. It makes it possible to load and , persist the entity. Unfortunately OpenAccess cannot work if a given entity doesn't implement this interface. All of your entities implement it because of our post build enhancement process and at the time being we cannot offer you an alternative.

    We consider extracting those interfaces to a simple "contracts" assembly. Then you should reference it in your layers above instead of the Telerik.OpenAccess.dll assembly and thus reduce your dependency to OpenAccess. Do you think such change would be helpful for you?

    Thank you for your understanding. 
     

    Regards,
    Kaloyan Nikolov
    Telerik
    OpenAccess ORM Q3 2013 Beta is available for immediate download in your account. Get it now and play with the latest bits. See what's new >>
  9. Myth
    Myth avatar
    54 posts
    Member since:
    Jan 2010

    Posted 10 Oct 2013 Link to this post

    I don't understand 100% what you are proposing. If it removes the need of my modules to implement anything else other than my base program i'm very much in favor. Even if it means some extra work in my base program.
  10. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 14 Oct 2013 Link to this post

    Hello Stijn,

    I would like to inform you that the task for reducing the dependencies to the Telerik.OpenAccess.dll will be evaluated during the Q3 SP1 planning session. I'll keep you updated when we have more details.

    Thank you for your valuable feedback.
     

    Regards,
    Kaloyan Nikolov
    Telerik
    OpenAccess ORM Q3 2013 Beta is available for immediate download in your account. Get it now and play with the latest bits. See what's new >>
  11. Myth
    Myth avatar
    54 posts
    Member since:
    Jan 2010

    Posted 14 Oct 2013 Link to this post

    Much appreciated. Looking forward to see the outcome already.

    Kind regards,
    Stijn
Back to Top
DevCraft banner