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.
9 Answers, 1 is accepted
- 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.
- 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.
- 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.
Zoran
the Telerik team
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();
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'
- 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.
Zoran
the Telerik team
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
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
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.
Kaloyan Nikolov
Telerik
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.
Kaloyan Nikolov
Telerik
Kind regards,
Stijn