This is a migrated thread and some comments may be shown as answers.

Using ORM First Time

21 Answers 294 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrew
Top achievements
Rank 1
Andrew asked on 19 May 2011, 08:59 PM
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?

21 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 20 May 2011, 04:07 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 23 May 2011, 10:13 AM

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.

:(
0
Andrew
Top achievements
Rank 1
answered on 25 May 2011, 11:49 AM
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?
0
PetarP
Telerik team
answered on 25 May 2011, 04:23 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 28 May 2011, 01:08 PM
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?
0
PetarP
Telerik team
answered on 28 May 2011, 01:14 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 28 May 2011, 02:40 PM
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?
0
Andrew
Top achievements
Rank 1
answered on 28 May 2011, 02:54 PM
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."

0
Andrew
Top achievements
Rank 1
answered on 31 May 2011, 04:29 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 31 May 2011, 11:17 PM

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

0
PetarP
Telerik team
answered on 01 Jun 2011, 04:42 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 01 Jun 2011, 07:44 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 02 Jun 2011, 02:49 PM

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.

0
Andrew
Top achievements
Rank 1
answered on 02 Jun 2011, 03:22 PM

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

0
Andrew
Top achievements
Rank 1
answered on 06 Jun 2011, 07:28 PM

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?

0
PetarP
Telerik team
answered on 07 Jun 2011, 04:15 PM
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.
0
Andrew
Top achievements
Rank 1
answered on 10 Jun 2011, 01:46 PM

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?

0
Andrew
Top achievements
Rank 1
answered on 13 Jun 2011, 10:22 PM

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.

0
Accepted
PetarP
Telerik team
answered on 15 Jun 2011, 04:08 PM
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.
0
Michael
Top achievements
Rank 1
answered on 09 Nov 2012, 08:27 PM
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.
0
Ivailo
Telerik team
answered on 13 Nov 2012, 11:47 AM
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.
Tags
Getting Started
Asked by
Andrew
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Andrew
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Ivailo
Telerik team
Share this question
or