Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Work-around for Struct with Entity Framework, Code-First approach

I'm currently constructing a database from an existing system with EF and code-first approach.

It is preferred that minimal changes is made to the 'core' classes. Because of this I would like to find a work-around for Structs and EF.

Is it possible to wrap a Struct into a class in any way so that EF can use the data within this Struct? Since EF are able to create its own Proxies of my 'core' classes, shouldn't I be able to this as well?

My knowledge about .Net, C# and EF is rather limited because I started to learn this language this year due to a bachelor assignment.

Any help would be highly appreciated.

Edit: Added examplecode.

Core has many classes that utilizes the TaxMode Struct, and store data in this Struct.

public class AcmeClass
{    
TaxMode Taxmode { get; set; }
}

The Struct is as follows:

public struct TaxMode
{
public string Name { get; set; }
public bool isTrue { get; set; }
}

Any attempt to add the properties of TaxMode into those classes only result in non-nullable errors.

like image 976
jonas Avatar asked Apr 04 '13 11:04

jonas


1 Answers

Structs are not supported.

You have to use class istead of it.

Updated

take a look at this Ladislav Mrnka answer

like image 85
MikroDel Avatar answered Oct 13 '22 01:10

MikroDel