How to map SQL_VARIANT in Entity Framework 6?

1

I'm using Entity framework 6 database first. There was already designed database and I need to use it to create an API. In severl tables [sql_variant] was used as a column type. When I added entity framework, all [sql_variant] columns were ignored with warning informing me that there is no mapping for this type!

I tried to manually add the [sql_variant] column with object type and map it. But I'm getting its value always null!

//The name of my [sql_variant] column is Value.
[Column("Value", TypeName = "sql_variant")]
[Required]
public object Value { get; set; }


//In the context class I tried to add also the following.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
 modelBuilder.Entity<MeasurementData>();
 modelBuilder.Properties<MeasurementData>();
}

I'm still getting the following exception:

System.NotSupportedException
  HResult=0x80131515
  Message=The specified type member 'Value' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>
c#
sql-server
entity-framework
entity-framework-6
asked on Stack Overflow Jul 3, 2019 by Firas

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0