locked
Creating an Entity Key RRS feed

  • Question

  • User-670712492 posted

    I have been trying to figure out how to use the Entity Framework and its class members for several days now but have been completely unsuccessful thus far.

     The main problem I have been encountering has been the following:

     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.Objects;
    using System.Data.Objects.DataClasses;

    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int intROW_ID = 1;
            object originalObject;

            RMXTrainingModel.SYS_PARMS tblSysParms = new RMXTrainingModel.SYS_PARMS();

            tblSysParms.PRIMARY_TITLE = "Mr.";

           
            RMXTrainingModel.SystemParametersEntity entities = new RMXTrainingModel.SystemParametersEntity();


            EntityKey key = new EntityKey("RMXTrainingModel.SYS_PARMS", "ROW_ID", intROW_ID);
            tblSysParms.EntityKey = key;



            entities.Attach(tblSysParms);
            //key = entities.CreateEntityKey("SYS_PARMS", tblSysParms);

            entities.Attach((IEntityWithKey)(tblSysParms));
            if (entities.TryGetObjectByKey(key, out originalObject))
            {
                tblSysParms.OC_FAC_ADDR3 = "Southfield";
                tblSysParms.P2_LOGIN = "csc";
                tblSysParms.P2_PASS = "csc";

                entities.ApplyPropertyChanges("SYS_PARMS", tblSysParms);
            }//if

            entities.SaveChanges();
        }
    }

     

    I am trying to create an Entity Key and assign the appropriate value to it, but I am unable to figure out what my qualifiedEntitySetName should be.  The documentation that I have found so far on ADO.Net Entity Framework is sparse at best and really does not provide good examples on how to do this or describe where the qualifiedEntitySetName attribute is derived from in the Entity Model. The prefix that I have been using "RMXTrainingModel" is the actual name of the my Entity Framework Model.  However, while attempting to use this code, an error occurs indicating that this is not recognized. 

     Any possible solutions or corrections to this code would be greatly appreciated.

    Thanks.

    Friday, September 19, 2008 10:30 PM

Answers

  • User1641955678 posted

    This forum is specific to ASP.NET Dynamic Data.  Your best bet is the Entity Framework forum.

    thanks,
    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 22, 2008 1:02 AM