Keep Getting Error |
![]() ![]() |
Keep Getting Error |
Jun 30 2009, 10:28 AM
Post
#1
|
|
|
|
The member with identity 'AEDM' does not exist in the metadata collection.
Parameter name: identity I keep getting above error when I am inserting updating from asp page using objectdatasource like in example in chapter 21. AEDM is namespace name like BAGA. Any ideas what's causing error? |
|
|
|
Jul 2 2009, 05:59 AM
Post
#2
|
|
|
|
I imagine that you've got something wrong with your insert code.
If it's not too long, do you want to paste that method into the forum? julie |
|
|
|
Aug 25 2009, 02:24 PM
Post
#3
|
|
|
|
I imagine that you've got something wrong with your insert code. If it's not too long, do you want to paste that method into the forum? julie Hi Julie, I am having the same problem but I'm not too shy to post my code I have a ClassSchedule object which contains SessionScheduleReference, InstructorReference, and ClassReference objects. From the ClassSchedule object, SessionSchedule is 1 to*; InstructorReference is * to 0-or-1; and Class is * - 1. As the book suggest, I have created xxx-Id properties for each of these references in a partial ClassSchedule class. However, when I attempt to insert a record, I get the following error: The member with identity 'Class' does not exist in the metadata collection.Parameter name: identity The xxx-Id members look like this: CODE public int? ClassId { get { if (ClassReference.EntityKey.EntityKeyValues.Count() > 0) return (int)ClassReference.EntityKey.EntityKeyValues[0].Value; else return null; } set { if (value != null) { ClassReference.EntityKey = new System.Data.EntityKey("CountyCollegeEntities.Class", "ID", value); } } } The code calling the insert: CODE ClassSchedule classSchedule = new ClassSchedule(); classSchedule.ClassId = int.Parse(ClassSelector.SelectedValue); classSchedule.SessionScheduleId = int.Parse(SessionSelector.SelectedValue); if (!string.IsNullOrEmpty(InstructorSelector.SelectedValue)) { classSchedule.InstructorId = int.Parse(InstructorSelector.SelectedValue); } classSchedule.AffiliateTaught = AffiliateSponsoredSwitch.Checked; classSchedule.Credits = byte.Parse(CreditsEntry.Text); classSchedule.Location = LocationEntry.Text; classSchedule.Notes = NotesEntry.Text; master.DataGateway.AddClassSchedule(classSchedule); master.DataGateway.SaveChanges(); And finally, the AddClassSchedule method: CODE public void AddClassSchedule(ClassSchedule classSchedule) { entity.AddToClassScheduleSet(classSchedule); } I really appreciate any help you can offer with this! Thanks, Vinney |
|
|
|
Aug 25 2009, 02:55 PM
Post
#4
|
|
|
|
Please correct me if I am doing this the hard way, but from what I found (http://msdn.microsoft.com/en-us/library/bb738695.aspx) was that for many-to-one relationships, you have to set the Value property of the EntityReference to the related object like this:
CODE ClassSchedule classSchedule = new ClassSchedule(); classSchedule.ClassReference.Value = master.DataGateway.GetClassById(int.Parse(ClassSelector.SelectedValue)); classSchedule.SessionScheduleReference.Value = master.DataGateway.GetSessionById(int.Parse(SessionSelector.SelectedValue)); I don't really like that this requires the 2 additional trips to the database. Is there anyother way around this (becides storing the values in the ViewState or Session). Thanks, Vinney |
|
|
|
Aug 26 2009, 03:24 PM
Post
#5
|
|
|
|
Vinny
The error is saying that when reading the metadata, the XML, it is not finding an EntitySet named "Class". Is it possible that the EntitySet for the "Class" entity is named "Classes"? When constructing the EntityKey you need the name of teh EntitySet. ?? Julie |
|
|
|
Aug 27 2009, 07:27 AM
Post
#6
|
|
|
|
When constructing the EntityKey you need the name of the EntitySet. Julie, Thanks for answering such a bonehead question, I was trying to reference the Navigation property!!! I have to be honest, I just recieved your book yesterday morning and skipped ahead to find the solution to my issue-which now appears to be a lack of understanding of the framework more than anything else. The funny thing is that last night I read about the differences between EntitySets and Navigation properties and today I find out that was my problem Thanks!! Vinney |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 7th November 2009 - 01:09 PM |