Entity CodeFirst EF6, EntityData string id

孤者浪人 提交于 2019-12-10 10:25:13

问题


Have started to use Entity Code First with Azure Mobile Services and have met some issue:

For using TableController with Entity objects I need to derive each of them from EntityData class, that provide string Id field!

I used to use int, long and even guid instead string for id, so...

What is benefits of this? What about insert operation and what is the best practice for this? What about performance for string id?


回答1:


@carlosfigueira has a good writeup about the change to using string id here: http://blogs.msdn.com/b/carlosfigueira/archive/2013/11/23/new-tables-in-azure-mobile-services-string-id-system-properties-and-optimistic-concurrency.aspx




回答2:


EntityData is a class which Dtos should implement because it is required for offline feature, at least was I got as answer.

To create a Table controller you need to use it, but you can ignore if you want... Suppose you have a class called "CarDto" the dto will have a property "carDto.Id" that is from EntityData, but you can create the "carDto.CarId" as your key! The only thing you need to do is create a model based in that you want and match it with your database and then use AutoMapper to match the car's model with car's dto :)

See Azure Mobile Services - Samples and articles to help developers to use Azure Mobile Services, which has a sample about to match dtos to model.

Or you can apply this approach Build a service using an existing SQL database with the Mobile Services .NET backend, but I do not like because in my opinion is confuse.... you choose what fits your needs :)



来源:https://stackoverflow.com/questions/28188393/entity-codefirst-ef6-entitydata-string-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!