2

While matching SQL Server datatypes with C# Code First Approach in Entity Framework, what are specific points that we should keep in mind so that our C# datatype should match exactly our SQL Server datatype?

Specifically, while we have to match SQL Server datatype to C# datatype, let's say for particular datatype hierarchyid, which exists in SQL Server but not in C#, how can we make it possible?

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked Aug 21, 2014 at 6:49
0

3 Answers 3

1

There's some datatype that's not supported by EF.

geography
geometry
hierarchyid
sql_variant

http://thedatafarm.com/data-access/sql-server-2008-data-types-and-entity-framework-4/

I never use any of that type, but when using dapper I also come to this similar problem(processing image datatype), the easiest way to deal with this limitation is just to go back to old OLE DB.

Other than that you just use this as a reference,

answered Aug 12, 2015 at 17:16
0

EF should handle the mapping of most datatypes. If you're using something that isn't handled you should be able to customize the mapping. Easiest would be to exclude mapping for unknown types, and save your object in a flattened way either in or related to the entity. Downside is that querying could be more work and you need to provide something to convert your object when reading and writing, but you're doing that maybe already when converting to viewmodels.

answered Jul 13, 2015 at 11:54
0

EF isolates your code from concrete database. Each database has it's own features but EF's API is not so powerfull to express them all. Actually, from the client's side EF is a simple object storage.

So, if you want to manage such database features like specific datatypes, security checks, triggers, views... EF can't help with it. I haven't seen anything that can help you. You need to introduce a dependency to the sql server in your system.

answered Aug 12, 2015 at 16:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.