none
[MyRowGuid] [uniqueidentifier] ROWGUIDCOL DEFAULT (newid()) RRS feed

  • Question

  • Hi,

    I have a table in Sql Server 2008 Expression like this:

    CREATE TABLE [dbo].[Industries](

    [IndustryID] [smallint] IDENTITY(1,1) NOT NULL,

    [ [MyRowGuid] [uniqueidentifier] ROWGUIDCOL NOT NULL,

    [MyRowVersion] [timestamp] NOT NULL,

     ....

    GO

     ALTER TABLE [dbo].[Industries] ADD CONSTRAINT [DF_Industries_MyRowGuid] DEFAULT (newid()) FOR [MyRowGuid]

    GO

     

    Now I am using Linq to Sql and the problem is:

    It understands and generates correct code for PK(Identity) and MyRowVersion(timestamp), they are read only and IsDBGenerated=True but not for MyRowGuid. I dont understand how I can tell Linq to Sql when it reads from database it should pay attention to the fact that MyRowGuid is ROWGUIDCOL  and has NewID()(it means IsDBGenerated=True and ReadOnly=True).

    I hope there is no need for me to go in generated code file and change stuff manually!

     

    Regards

    Sunday, August 31, 2008 11:29 AM

Answers

  • LINQ to SQL cannot see where tables have default values on columns: I have the same issue where I have a CreatedDate column which has a default value GetDate() on SQL.

     

    See my FAQ entry

     

    The solution is to (a) manually alter the dbml to IsDBGenerated=true or set the values in your code by handling the onCreated event

    Tuesday, September 2, 2008 1:42 PM
    Answerer