Quantcast
Channel: EntityFramework Reverse POCO Code First Generator
Viewing all articles
Browse latest Browse all 1642

Edited Feature: using DB "newsequentialid()" to help with indexing [174]

$
0
0
We have a database that now has a surrogate key that we use for lookup. We have it set as a "UniqueIdentifier" and have a default value of "newsequentialid()". We want to use the sqeuential id from MSSQL as when when index on the value it will make for better paging. I have changed the code in the core ttinclude to set the column as "IsStoreGenerated" = 1. Here is the code that i have created.

```
CAST(CASE WHEN COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)), c.COLUMN_NAME, 'IsIdentity') = 1 THEN 1
WHEN COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)), c.COLUMN_NAME, 'IsComputed') = 1 THEN 1
WHEN DATA_TYPE = 'TIMESTAMP' THEN 1
WHEN DATA_TYPE = 'UNIQUEIDENTIFIER' AND ISNULL(COLUMN_DEFAULT, '') = '(newsequentialid())' THEN 1
ELSE 0
END AS BIT) AS IsStoreGenerated,
```
I did not change the constructor of the class as since the column will now be set to "HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed)" and EF will ignore the value anyway

Viewing all articles
Browse latest Browse all 1642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>