I'm using EntityFramework 6.1.3, database-first. I am currently wishing I had chosen code-first...
I have a database with some tables. I've previously
built my edmx off of these tables. Then I changed the type of a few columns and added a few columns. For instance, changing a bit
column to an int
column.
I try and update my model from the database, using right-click -> Update Model from Database
.
It seems that no matter what I do, EF will only ever pick up the state of my database as it was when I created the edmx. Things I have tried:
When I right-click my entity and select "Table Mapping", it always always shows the old bit
column on the left.
Here's my database table design:
It might be of note that the entity is going off a view, not directly off of the table. But the view is literally a select * of the table as I am investigating this issue, and I have confirmed with powershell that the type returned by the view is an int:
PS> $conn = new-object data.sqlclient.SqlConnection("data source=localhost;initial catalog=dbname;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework")
PS> $conn.open()
PS> $query = $conn.createcommand()
PS> $query.commandtext = "select * from [dbname].[LocalCustom].[viewname]"
PS> $reader = $query.executereader()
PS> $reader.getschematable().rows[19]
ColumnName : ActiveMember
ColumnOrdinal : 19
ColumnSize : 4
NumericPrecision : 10
NumericScale : 255
IsUnique : False
IsKey :
BaseServerName :
BaseCatalogName :
BaseColumnName : ActiveMember
BaseSchemaName :
BaseTableName :
DataType : System.Int32
AllowDBNull : False
ProviderType : 8
IsAliased :
IsExpression :
IsIdentity : False
IsAutoIncrement : False
IsRowVersion : False
IsHidden :
IsLong : False
IsReadOnly : False
ProviderSpecificDataType : System.Data.SqlTypes.SqlInt32
DataTypeName : int
XmlSchemaCollectionDatabase :
XmlSchemaCollectionOwningSchema :
XmlSchemaCollectionName :
UdtAssemblyQualifiedName :
NonVersionedProviderType : 8
IsColumnSet : False
My MAIN QUESTION I have at this time is... How does EF know that it used to be a bit
type? Where is it storing this data?? Of course I would also like to know how to properly update the model using the UI without having to delete and re-add entities or whatever else I'm going to have to do to get it to update.
I'm pretty frustrated with EF :(
This is the case I often meet when using Entity Framework database-first. When you make some changes from the database, to update EF, you should:
right-click -> Update Model from Database -> check that table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With