The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

adding record to access db with guid primary key

Last post 02-12-2008, 9:45 PM by mike92117. 2 replies.
Sort Posts: Previous Next
  •  02-12-2008, 12:33 PM 8031

    adding record to access db with guid primary key

    I've been using ES almost exclusively with SQL Server 2005, but I have a module that must use an existing access db.

    I have no problem reading.  I do have a problem with inserts.  I tried to add a record using standard ES syntax.  When the code runs, no record is added, no exceptions are thrown, the code just acts like it worked.  Except looking at the table, no record is added.  The access db has a primary field that is a Guid.  When I tried it as autoinc, it worked as expected.
     

     

    Code:
    MailingListCollection mlc = new MailingListCollection();
    MailingList ml = mlc.AddNew();
    ml.Person = tbName.Text;
    ml.Email = tbEmail.Text;
    mlc.Save();
     
    Mike
  •  02-12-2008, 9:17 PM 8042 in reply to 8031

    Re: adding record to access db with guid primary key

    MS Access has two types of AutoNumber fields, Replication Id (Guid), and Long Integer. EntitySpaces currently only supports Long Integer for AutoIncrements. As a work-around, if you need the Guid primary key, you will have to manually open the generated class. Scroll down to the table's Metadata class constructor, and change "c.IsAutoIncrement = true;" to "c.IsAutoIncrement = false;". Then, add the following AddNew() override to the custom entity class, where "GuidKey" is the name of the PK field:

    Code:
    namespace BusinessObjects
    {
        public partial class Table1 : esTable1
    	{
            public override void AddNew()
            {
                base.AddNew();
                this.GuidKey = System.Guid.NewGuid();
            }
        }
    }

    David Neal Parsons
    www.entityspaces.net
  •  02-12-2008, 9:45 PM 8043 in reply to 8042

    Re: adding record to access db with guid primary key

    Thanks - that was easy and worked like a charm.  Just gotta remember if / when I regenerate, to change the flag.

    Mike
View as RSS news feed in XML