Programming Entity Framework
Programming Entity Framework By Julia Lerman
February 2009
Pages: 828


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Keep Getting Error
marinnn
post Jun 30 2009, 10:28 AM
Post #1


New Member
*

Group: Members
Posts: 1
Joined: 30-June 09
Member No.: 18,944



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? blink.gif
Go to the top of the page
 
+Quote Post
JulieLerman
post Jul 2 2009, 05:59 AM
Post #2


Active Member
****

Group: O'Reilly Author
Posts: 100
Joined: 17-September 08
Member No.: 836



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
Go to the top of the page
 
+Quote Post
vinneyk
post Aug 25 2009, 02:24 PM
Post #3


New Member
*

Group: Members
Posts: 3
Joined: 25-August 09
Member No.: 19,882



QUOTE (JulieLerman @ Jul 2 2009, 05:59 AM) *
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 smile.gif

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
Go to the top of the page
 
+Quote Post
vinneyk
post Aug 25 2009, 02:55 PM
Post #4


New Member
*

Group: Members
Posts: 3
Joined: 25-August 09
Member No.: 19,882



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
Go to the top of the page
 
+Quote Post
JulieLerman
post Aug 26 2009, 03:24 PM
Post #5


Active Member
****

Group: O'Reilly Author
Posts: 100
Joined: 17-September 08
Member No.: 836



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
Go to the top of the page
 
+Quote Post
vinneyk
post Aug 27 2009, 07:27 AM
Post #6


New Member
*

Group: Members
Posts: 3
Joined: 25-August 09
Member No.: 19,882



QUOTE (JulieLerman @ Aug 26 2009, 03:24 PM) *
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!!! rolleyes.gif

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 laugh.gif ...And this is the reason I've decided to read this book from the beginning.

Thanks!!
Vinney
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 7th November 2009 - 01:09 PM