locked
EF 4.1 and ROWGUIDs RRS feed

  • Question

  • We'd like to use EF 4.1 as part of a replication strategy.  SQL server 2008 R2 replication requires a column in each table to be marked as a ROWGUID in order to uniquely identify that row.  Using EF 4.1, is it possible to denote which column is a ROWGUID?  We can and are using the
    HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
    
     clause, but that doesn't mark something as a ROWGUID.  Is this functionality available?
    Monday, April 25, 2011 6:40 PM

Answers

  •  

    Hi Rick,

    Welcome!

    According to your description, there is not ROWGUID attribute denoting your properties. DatabaseGeneratedOption set to Identity: the database generates a value when a row is inserted. But Code First doesn’t support set default values, I think you should set the column's default values manually. Alternatively, you could probably set the default value in your POCO's constructor. (http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a091ccd6-0ba8-4d4f-8f5e-aafabeb258e4/). Thanks for understanding.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Rick Langel Tuesday, April 26, 2011 12:01 PM
    Tuesday, April 26, 2011 7:30 AM
  • As we are trying to automate the deployment process, having to manually change the schema to support another Sql Server technology isn't the greatest solution. 
    • Marked as answer by Rick Langel Tuesday, April 26, 2011 12:04 PM
    Tuesday, April 26, 2011 12:04 PM

All replies

  •  

    Hi Rick,

    Welcome!

    According to your description, there is not ROWGUID attribute denoting your properties. DatabaseGeneratedOption set to Identity: the database generates a value when a row is inserted. But Code First doesn’t support set default values, I think you should set the column's default values manually. Alternatively, you could probably set the default value in your POCO's constructor. (http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a091ccd6-0ba8-4d4f-8f5e-aafabeb258e4/). Thanks for understanding.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Rick Langel Tuesday, April 26, 2011 12:01 PM
    Tuesday, April 26, 2011 7:30 AM
  • As we are trying to automate the deployment process, having to manually change the schema to support another Sql Server technology isn't the greatest solution. 
    • Marked as answer by Rick Langel Tuesday, April 26, 2011 12:04 PM
    Tuesday, April 26, 2011 12:04 PM