How to determine the structure of an entity, how to save instances of a custom type (which can be saved as a scalar)

One of my entity classes can be stored on the sql server of the database as BIGINT. My question is: how to get Entity Framework structure? context to know how to store and retrieve instances of my object class?

More details. I use Noda Time , which can represent a (much larger) range of dates than SQL or .NET datetime can (And this is a dope dessert). My Entity Class, Happening, is a wrapper around the NodaTime Instant Class. I can set Happening from long and get from going on with methods such as .SetFromLong (long moment) and .ToLong ().

My model is currently working for me, saving classes that contain properties of the dotTime type dotTime. If instead I want to use the properties of my custom "Happening" type, how can I tell the Entity Framework how to save them?

If I read this article on modeling and cartography, am I on the right track or skipping something simpler?

http://msdn.microsoft.com/en-us/library/bb896343.aspx

I am using framework 4 entity.

+6
source share
1 answer

What I recommend doing is to add 2 properties to the NodaTime entities and long and to exclude your NodaTime property using [NotMapped] in your EF model and then in your update getter / setter.

t

public class MyEntity{ public long TimeAsLong{get;set;} [NotMapped] public Happening { get{ return new Happening().SetFromLong(TimeAsLong); } set { TimeAsLong = value.ToLong(); } } } 

The effect of this will be that long is stored in db, but you can access it in the class via NodaTime

+6
source

Source: https://habr.com/ru/post/909380/


All Articles