I am getting this uncaught exception: Parent entity is not in the parent entity set for this association. using upshotjs. I think the problem is that even though i declare my data
model is not matching or binded to the metadata model.
I have something like this in my ViewModel
UserModel ={
CountryModel
LanguageModel
}
var dataSourceOptions = {
providerParameters: { url: options.serviceUrl, operationName: "GetUsers" },
entityType: entityType,
bufferChanges: true,
mapping: MyApp.User
};
var editorDataSource = new upshot.RemoteDataSource(dataSourceOptions);
var countriesDataSource = new upshot.RemoteDataSource({
providerParameters: { url: options.serviceUrl, operationName: "GetCountryOptionsForUser", operationParameters: parentEntitiesOperationParameters },
entityType: "Country:#MyApp.Core.Entities",
dataContext: editorDataSource.getDataContext()
});
the countriesDataSource gets all the countries and languages.
CountryModel={
Name
Languages <- Array of Language Models
}
If I supply the dataContext option then this is not a problem but I have another model inside the Country Model call Languages and this Language model is not binded or mapped to the one supplyed by the metadata model. How can I bind the raw data to the DataSource?
I try using the editorDataSource.getDataContext().addMapping(MyApp.Language.Type, MyApp.Language) but this does not seem to work.
The mapping must represent the data you get back from the service. If you retrieve your data from the server it's always an IQueryable of a certain type. The complete model of this type must recreated in a JS object, then this object can be mapped an represent
your object(s) you get back from the server. In your case i think you have only mapped one of the child objects.
could you please explain how to map my child objects. As I understand when you fetch data using
RemoteDataSource and if you supply the mapping model then I thought it would automatically mapped all the child objects as well.
yes i understand that part. The problem here and i think is a bug or something is that when you get the Json from the server it gets a __type: property with upshot and i think upshot need this __type to bind the model but the problem is that if you have
class as below:
[DataContract(Name = "Country")]
public class CountryViewModel()
{
[Key]
[DataMember]
public int Id {get;set;}
[DataMember]
public string Name {get;set;}
[DataMember]
public IEnumerable<Language> Languages {get;set;}
}
[DataContract(Name = "Language")]
public class LanguageViewModel()
{
[Key]
[DataMember]
public int Id {get;set;}
[DataMember]
public string Name {get;set;}
}
If you do a remotedataaccess then this would fetch a json data something like this :
This data when binded, upshot only knows the one with the __type Model and but for the Language model it does not have the __type so it does not bind properly. How can I get the __type on the Languages property?
None
0 Points
4 Posts
uncaught exception: Parent entity is not in the parent entity set for this association.
Apr 23, 2012 11:38 PM|maranganator|LINK
I am getting this uncaught exception: Parent entity is not in the parent entity set for this association. using upshotjs. I think the problem is that even though i declare my data model is not matching or binded to the metadata model.
I have something like this in my ViewModel
UserModel ={
CountryModel
LanguageModel
}
var dataSourceOptions = {
providerParameters: { url: options.serviceUrl, operationName: "GetUsers" },
entityType: entityType,
bufferChanges: true,
mapping: MyApp.User
};
var editorDataSource = new upshot.RemoteDataSource(dataSourceOptions);
var countriesDataSource = new upshot.RemoteDataSource({
providerParameters: { url: options.serviceUrl, operationName: "GetCountryOptionsForUser", operationParameters: parentEntitiesOperationParameters },
entityType: "Country:#MyApp.Core.Entities",
dataContext: editorDataSource.getDataContext()
});
the countriesDataSource gets all the countries and languages.
CountryModel={
Name
Languages <- Array of Language Models
}
If I supply the dataContext option then this is not a problem but I have another model inside the Country Model call Languages and this Language model is not binded or mapped to the one supplyed by the metadata model. How can I bind the raw data to the DataSource? I try using the editorDataSource.getDataContext().addMapping(MyApp.Language.Type, MyApp.Language) but this does not seem to work.
Member
50 Points
23 Posts
Re: uncaught exception: Parent entity is not in the parent entity set for this association.
Apr 24, 2012 02:30 AM|KDegrave|LINK
The mapping must represent the data you get back from the service. If you retrieve your data from the server it's always an IQueryable of a certain type. The complete model of this type must recreated in a JS object, then this object can be mapped an represent your object(s) you get back from the server. In your case i think you have only mapped one of the child objects.
greetings
Kristof
Ria4HTML: http://ria4htmldemo.codeplex.com
Linq2IndexedDB: http://linq2indexeddb.codeplex.com
None
0 Points
4 Posts
Re: uncaught exception: Parent entity is not in the parent entity set for this association.
Apr 24, 2012 04:02 AM|maranganator|LINK
could you please explain how to map my child objects. As I understand when you fetch data using RemoteDataSource and if you supply the mapping model then I thought it would automatically mapped all the child objects as well.
Member
50 Points
23 Posts
Re: uncaught exception: Parent entity is not in the parent entity set for this association.
Apr 24, 2012 04:34 AM|KDegrave|LINK
Hi,
You can do this as follow:
For more info you can take a look at my sample application http://ria4htmldemo.codeplex.com/
Greetings
Kristof
Ria4HTML: http://ria4htmldemo.codeplex.com
Linq2IndexedDB: http://linq2indexeddb.codeplex.com
None
0 Points
4 Posts
Re: uncaught exception: Parent entity is not in the parent entity set for this association.
Apr 24, 2012 07:39 AM|maranganator|LINK
yes i understand that part. The problem here and i think is a bug or something is that when you get the Json from the server it gets a __type: property with upshot and i think upshot need this __type to bind the model but the problem is that if you have class as below:
If you do a remotedataaccess then this would fetch a json data something like this :
This data when binded, upshot only knows the one with the __type Model and but for the Language model it does not have the __type so it does not bind properly. How can I get the __type on the Languages property?
Member
50 Points
23 Posts
Re: uncaught exception: Parent entity is not in the parent entity set for this association.
Apr 24, 2012 08:20 AM|KDegrave|LINK
I think the problem you are struggling with is:
you need to provide the metadata of your objects. If you use Steven Sandersons demo, you can use the following line of code:
This will configure the metadata u need and configure upshot for you.
Take a look what it generates, and then you can use it manually if you want to.
greetings
Kristof
Ria4HTML: http://ria4htmldemo.codeplex.com
Linq2IndexedDB: http://linq2indexeddb.codeplex.com