Can't add an object using EF and SQL Compact

Posted by kamilo on Stack Overflow See other posts from Stack Overflow or by kamilo
Published on 2010-03-28T15:25:31Z Indexed on 2010/03/28 15:33 UTC
Read the original article Hit count: 142

Filed under:

Hello,

I have some very simple SQL Compact database. I would like to use Entity Framework to access the database but for some reason I can't add an object to this database using EF.

Here is the code

using (pos_inglotEntities posInglotCtx = new pos_inglotEntities())
            {
                posInglotCtx.Connection.Open();

                CT_POS_OITM item = new CT_POS_OITM() { ItemCode = "123", ItemName="abc"};

                try
                {
                    posInglotCtx.AddToCT_POS_OITM(item);
                    posInglotCtx.SaveChanges();
                }
                catch (Exception e) { }

                posInglotCtx.Connection.Close();
            }

After running this code my database is still empty although if I run it once again I get "duplicate values" exception. But again database is empty.

I created this db using PrimeWorks conversion tool from standard sql server database.

What is going on?

Thanks in advance

© Stack Overflow or respective owner

Related posts about sqlcompact