Entity CodeFirst EF6, EntityData string id

2019-05-17 18:22发布

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?

2条回答
叼着烟拽天下
3楼-- · 2019-05-17 18:59

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 :)

查看更多
登录 后发表回答