Map Guid Property to Oracle in Entity Framework Code First

ぐ巨炮叔叔 提交于 2019-12-07 08:38:53

问题


I am trying to map a Guid property to Oracle. Here's its declaration:

[Key]
[Column(Order = 0, TypeName = "RAW")]
[MaxLength(16)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }

However, I keep getting the following exception:

Schema specified is not valid. Errors:

(7,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Guid[Nullable=False,DefaultValue=]' of member 'Id' in type 'Model.Test' is not compatible with 'OracleEFProvider.raw[Nullable=False,DefaultValue=,MaxLength=2000,FixedLength=False]' of member 'Id' in type 'CodeFirstDatabaseSchema.Test'.

What am I missing?

Thanks!

RP


回答1:


I have given up, since I got no response from either Oracle or Microsoft. As far as I can tell, there is no way to have Entity Framework Code First use Guids on Oracle. I am using a String instead of the Guid, but I still populate it with a Guid.NewGuid().ToString(), so that I have a unique primary key.




回答2:


The issue here is that there is no direct mapping of the Oracle Data Type of "RAW(16)" to the EDM type of "Guid". You can find this information in the Developer Guide at:

https://docs.oracle.com/database/121/ODPNT/entityEDMmapping.htm#ODPNT8275

We had run into the same exact issue, but was able to solve it by simply removing the configuration of the "TypeName" property on the [Column] attribute. Below is a sample of how we decorated our code-first Entity property.

[Column("ColumnName")]
public Guid Uid{ get; set; }

I don't know why this work, but it just does. Hopefully Oracle updates their EF library to be able to use something like TypeName = "RAW(16)". Hope this helps.



来源:https://stackoverflow.com/questions/18813349/map-guid-property-to-oracle-in-entity-framework-code-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!