How to map column and entity propery of different datatypes in entity framework code first

后端 未结 5 1246
北恋
北恋 2020-12-10 14:33

I am using Entity Framework 5 - Code first.

I have a database that I am connecting to that already exists for some time now (I did not create it). There is a table

5条回答
  •  抹茶落季
    2020-12-10 14:59

    Another option to work out what the code first should be is to the MS EF Powertools http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d

    You can add an empty project, right click, EF Reverse engineer code first from DB.

    You often (not always) get a good start to the solution. Did you try using decimal?

    public class Customer : IEntity
    {
     public decimal Id { get; set; }
    
     public string FirstName { get; set; }
    
     public string LastName { get; set; }
    }
    

    if you are concerned precision, you should add validation to the POCO.

    There are also some interesting Anotation hacks you may like. http://geekswithblogs.net/danemorgridge/archive/2010/12/20/ef4-code-first-control-unicode-and-decimal-precision-scale-with.aspx good luck

提交回复
热议问题