简体   繁体   English

无法将“表1”上的“ Id”属性设置为“ System.Byte []”值。 您必须将此属性设置为“ System.Guid”类型的非空值

[英]The 'Id' property on 'Table1' could not be set to a 'System.Byte[]' value. You must set this property to a non-null value of type 'System.Guid'

I am using Code First with Oracle 12c . 我在Oracle 12c使用Code First。 I have a class 我有一堂课

public class Table1
{
  public Guid Id { get; set; }
  public string SomeOtherStuff { get; set; }
} 

Entity Framework converts Id to RAW 实体框架将ID转换为RAW

CREATE TABLE "FB"."Media" 
   (    "Id" RAW(16) NOT NULL ENABLE, ...

So now if I do this: 所以现在如果我这样做:

var list = db.Table1.SqlQuery("select * from Table1")).ToList();

I get an error 我得到一个错误

The 'Id' property on 'Table1' could not be set to a 'System.Byte[]' value. 无法将“表1”上的“ Id”属性设置为“ System.Byte []”值。 You must set this property to a non-null value of type 'System.Guid'}` 您必须将此属性设置为'System.Guid'}类型的非空值。

Edit: I am using Oracle.ManagedDataAccess.EntityFramework 6.121.2.0 编辑:我正在使用Oracle.ManagedDataAccess.EntityFramework 6.121.2.0

The problem is that your Oracle EF provider maps Guid to the Raw type, but in turn, the Raw is mapped to a byte array. 问题是您的Oracle EF提供程序将Guid映射到Raw类型,但是将Raw映射到字节数组。

You could try specifying the column type yourself, if your provider supports it (depending on your provider, it might not). 如果提供者支持,则可以尝试自己指定列类型(取决于提供者,可能不支持)。

public class Table1
{

  [Column("Id", TypeName="VARCHAR(50)")]
  public Guid Id { get; set; }
  public string SomeOtherStuff { get; set; }
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法设置为'System.Decimal'值。 您必须将此属性设置为类型为“System.Double”的非null值 - could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double' 无法将“ y”的“ x”属性设置为“ System.Decimal”值。 您必须将此属性设置为“ System.Boolean”类型的非空值 - The 'x' property on 'y' could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Boolean' 无法将“ tblX”上的属性“ x”设置为“空”值。 您必须将此属性设置为'Int16'类型的非空值 - The property 'x' on 'tblX' could not be set to a 'null' value. You must set this property to a non-null value of type 'Int16' Y的X属性不能设置为“十进制”值。 您必须将此属性设置为“ Single”类型的非空值 - The X property on Y could not be set to a 'Decimal' value. You must set this property to a non-null value of type 'Single' 将属性设置为“ System.Double”类型的非空值 - Set a property to a non-null value of type 'System.Double' 无法将属性设置为字节值,必须将该属性设置为int32类型的非null - Property could not be set to a byte value you must set the property to a non null of type int32 如何摆脱'属性无法设置为double值,必须将此属性设置为decimal类型的非null值' - How to get rid of 'property could not be set to a double value, you must set this property to a non-null value of type decimal' 带有 Informix 的实体框架; - 如何修复您必须将此属性设置为“Double”类型的非空值 - Entity Framework with Informix; - How to fix You must set this property to a non-null value of type 'Double' 无法设置为Double类型的非Double类型的非零值 - Could not be set to a Double value, non-null value of type Single JSON 值无法转换为 System.Byte[] - The JSON value could not be converted to System.Byte[]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM