0

I have two tables APP in two databases, I want to get the same App identifier in the two databases, but when I insert the app into the first database and insert it in the second database I have either a new Guid generated (if I specify a default value in my column) or a null guid.

here's my code of inserting the app in the two tables of the databases:

 app.Id_App = Guid.NewGuid();
            app.DateAdded = DateTime.Now;
            app.PublisherId_advertiserPublisher = id_publisher;
            db.AppSet.AddObject(app);
            db.SaveChanges();

            //add app to db2


            App2 appDB2 = new App2()
            {
                App_link=app.App_link,
                Id_app= app.Id_App,                   
                CategoryId_cat=app.CategoryId_cat,
                Description=app.Description,
                keywords=keywords.Key_word,             
            };
       DB2.App.AddObject(appDB2);
            pushDB.SaveChanges();

I've already turned rowGuid in table definition to no. have I missed something? is there a better way to get the same guid key in two different databases? thanks.

Yasmine GreenApple
  • 438
  • 1
  • 5
  • 15
  • Please show the entity declarations (class App and App2). – Pierre Arlaud Nov 26 '13 at 10:19
  • 2
    `Guid` is not some magic type that behaves differently from all other types. If your model doesn't have any special information about a `uniqueidentifier` column, it's updateable by doing exactly what you're doing now. I'm pretty sure your model does have some special information that says the column is server-calculated. Get rid of that. Where to look for that special information depends on how your model is constructed. –  Nov 26 '13 at 10:20

1 Answers1

1

If you originally specified that Id_app should be database generated, then changed it to DatabaseGenerated.None, entity framework does not issue sql to alter the underlying table. You will need to drop and re-create the table or manually alter it in the database or create a custom migration.

References:

Drop identity using entity framework

Switch IDENTITY on/off with custom migration

Migrations: does not detect changes to DatabaseGeneratedOption - you can vote for it in a future version here

Community
  • 1
  • 1
Colin
  • 22,328
  • 17
  • 103
  • 197
  • you are right, I've changed it from Identity to none, but I didn't have to recreate the table, I changed it in the xml of the entity framework and the database, thank you for your help, it works. – Yasmine GreenApple Nov 27 '13 at 09:15