JonDouglas / EntityFrameworkWithXamarin

Code to accompany a blog post on EF
20 stars 10 forks source link

Added an iOS project to the sample #2

Closed cwrea closed 6 years ago

cwrea commented 7 years ago

(Relates to the sample for your blog post at https://blog.xamarin.com/building-android-apps-with-entity-framework. Thanks for that!)

Now that Xamarin.iOS 10.10 addressed the NotImplementedException blocker bug (https://github.com/aspnet/EntityFramework/issues/7158), I updated your sample to include a new iOS project that runs the same EF Core code example from the Droid project.

Getting the iOS app to run the same EF Core code successfully in the iOS simulator was straightforward with the new bits. However, getting the iOS app to run that EF Core code on an a physical iOS device took a bit more work:

Xamarin's default build configurations targeting the iOS simulator do not perform the linking that is typical of a device build. When targeting a device, the Xamarin linker removes unreferenced SDK types and methods from generated code. However, EF Core's query parser refers to certain SDK types and methods only via reflection. (e.g. search the EF Core repo for instances of GetRuntimeMethod.)

The linker directives in the iOS project's LinkDescription.xml file ensure the iOS app can run successfully on a physical iOS device. (I included a reference to this file via project settings "Additional mtouch arguments", as Visual Studio 2017 on PC is lacking the LinkDescription "Build Action" that is available on Visual Studio for Mac / Xamarin Studio.)