Yes, I can confirm that 15.7 preview solves the problem, don't forget to also install the update on the Mac.
But... it gives problems, building of the app fails most of the time with random errors, and when it build and starts on the iPhone it now gives a 'The App has been terminated'. ...(It actually started once, I saw the problem was gone, but can not start the App again)
If you want to start a similar project today, I suggest you use the built-in project templates. You can do so via File > New > Project in the menu, and select Visual C# > Cross-Platform in the left hand side of the New Project dialog, and then choose Mobile App (Xamarin.Forms) from the list of project templates, and then the Blank App template in the dialog that follows. Be sure to choose .NET Standard as the Code Sharing Strategy.
Pay attention to some of the current workarounds earlier in this thread. Notably, for the Android project you may want to add a packages.config to your project instead of using the new PackageReference-style references in the *.csproj file, as there is an open issue where using packages.config is a workaround.
@davefxy said:
How did you know what packages to put into the packages.config file? If these are not listed in the csproj file?
Start with a valid but empty packages.config in your Android project. (See first example below.) Then use the "Manage NuGet Packages" menu item (available if you right-click your project's References) to find and install the necessary packages. Start with Xamarin.Forms, and Microsoft.EntityFrameworkCore.Sqlite for EF Core. The package manager, by default, pulls in the package you ask for, and the packages that it in turn depends on. If you open your packages.config after installing packages, you'll see that's where they end up. (See second example below.)
Here's what a valid but empty packages.config file looks like:
How can you say this works I am trying to get data annotations to work in the standard way and it doesnt. I am using these in my dbcontext in my web api and I want to be transpose it from json to an object so doesnt xamrian still need the dataannotation to understand that in the form of.
My web api returns json so for example I have the following
[code]
public class FuelWc : IHttpService
{
readonly IJsonConverter jsonConverter;
public FuelWc()
{
}
public FuelWc(IJsonConverter jsonConverter)
{
this.jsonConverter = jsonConverter;
}
public async Task<T> Get<T>(string url)
{
using (var client = new System.Net.Http.HttpClient())
{
var response = await client.GetAsync(url);
var json = await response.Content.ReadAsStringAsync();
return jsonConverter.Deserialize<T>(json);
}
}
However cause xamrain forms doesn't understand data notations how can i keep my models the same for ef and for the Deserialize of the json to the .net object.
i use the following
[code]
public class JobsList
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; } // int
public int? EnginerId { get; set; } // int
public int? ClientId { get; set; } // int
public DateTime? StartTime { get; set; } // date
public DateTime? EndTime { get; set; } // date
[MaxLength]
public string Notes { get; set; } // nvarchar(max)
[MaxLength(150)]
public string photo { get; set; } // nvarchar(150)
public int? AssignedTo { get; set; } // int
public int? CompletedBy { get; set; } // int
public DateTime? CreatedDate { get; set; } // date
public DateTime? CompletedDate { get; set; } // date
public int? Components { get; set; } // int
public int? JobStatus { get; set; } // int
@ChrisWRea You're a true pioneer - thanks for putting this together. Question - now that this issue is closed - what needs to be updated? Or do you have plans to update your sample?
@MarkZhukovsky You're welcome. I was intending to revisit the sample when Entity Framework Core 2.1 is released. I'll remove any unnecessary workarounds then (i.e. System.Runtime.CompilerServices.Unsafe) that may have been required prior to VS 15.7.x.
Good day sir Chris, How can I do this with an existing sqlite database? Also, where can I locate the local database created with the code used in this solution?
As for where you can find the local database in the Todo sample, it will vary based on the platform. Look for the FileHelper.cs file within each platform project and there you'll see where the database path gets constructed. Here is the iOS app's FileHelper.cs: https://github.com/cwrea/XamarinTodo/blob/NETStd20_EFCore203/Todo.iOS/FileHelper.cs. You might modify yours to output the return value to debug output, so you can see the full path. On my Mac, I use a tool called iExplorer to grab copies of the SQLite database from the app's Library/Databases folder.
As I stopped by this thread a few moments ago, I thought I would remark that I have tried to adapt the sample for Entity Framework Core 2.1 which came out a couple of weeks ago, but there remain issues preventing it from being compiled with Xamarin.iOS.
Anybody interested in following EF Core progress on Xamarin should check out these recent/open GitHub issues:
As for the ER Core adaptation of the XamarinTodo sample, the most recent published version is on EF Core 2.0.3: https://github.com/cwrea/XamarinTodo/tree/NETStd20_EFCore203. I removed some workarounds that are now unnecessary on Visual Studio 15.7.x. e.g. the projects now use package references instead of package.config.
Once I get a version successfully building and running on EF Core 2.1, I'll post an update here.
It has been confirmed that Azure Mobile Apps unfortunately will not support .NET Core, so the offline sync capability (that comes in their starter solution) with .net core backend is off the table.
Offline-first approach with bidirectional synchronization would really take this sample to the next level. Wondering if you've given this any thought? I was considering playing around with this free library for SQLite syncing to a SQL db on Azure. @ChrisWRea
@JohanMulder I can't say as I haven't had the time to try yet, assuming you are referring to having tried with the recent release of Visual Studio 15.8. Client work keeping me busy.
@ChrisWRea, VS 15.8.1 appears to fix the System.Memory compile error for iOS (github.com/xamarin/xamarin-macios/issues/4168) and I am able to deploy to a physical device, but I am still getting the AOT error related to Nullable columns.
When you circle back to this, I would be interested to know if you are seeing similar behavior, as the Nullable columns issue is marked as "Closed" in GitHub (github.com/aspnet/EntityFrameworkCore/issues/9249) and "RESOLVED FIXED" in the Xamarin Bugzilla (bugzilla.xamarin.com/show_bug.cgi?id=59184) and (bugzilla.xamarin.com/show_bug.cgi?id=58424).
As I am starting a new project and face the decision which ORM (or DAL) to use, I stumbled upon this amazing thread.
Thanks @ChrisWRea.
I managed to integrate EF Core 3.1 into my project but I also got some exceptions while trying to do basic stuff.
Which make me wonder if EF Core is production ready at this point.
What have your experiences been so far, Xamarin Community? Thanks!
i wonder how is the performance on cascading and getting parent with children on multiple level.
For example, if you want to get a school object with all classes and all students as 3 layers. How fast it ist?
and if you delete a school object to cascade delete on all related classes and students.
Based on my experience sqlite-net was super slow. thats why i decided to use akavache which is based on sqlite as well but working asynchronous key value store.
Posts
@Christian
Yes, I can confirm that 15.7 preview solves the problem, don't forget to also install the update on the Mac.
But... it gives problems, building of the app fails most of the time with random errors, and when it build and starts on the iPhone it now gives a 'The App has been terminated'. ...(It actually started once, I saw the problem was gone, but can not start the App again)
Ben
Could you describe the steps you performed in Visual Studio to create the Todo project? I apologize for the hand holding required.
Hi @davefxy. I didn't create the project. The sample is adapted from this Xamarin sample described in the docs. I merely ported it to use EF Core instead of sqlite-net.
If you want to start a similar project today, I suggest you use the built-in project templates. You can do so via
File > New > Project
in the menu, and selectVisual C# > Cross-Platform
in the left hand side of the New Project dialog, and then chooseMobile App (Xamarin.Forms)
from the list of project templates, and then theBlank App
template in the dialog that follows. Be sure to choose.NET Standard
as the Code Sharing Strategy.Pay attention to some of the current workarounds earlier in this thread. Notably, for the Android project you may want to add a
packages.config
to your project instead of using the new PackageReference-style references in the *.csproj file, as there is an open issue where usingpackages.config
is a workaround.How did you know what packages to put into the packages.config file? If these are not listed in the csproj file?
Start with a valid but empty
packages.config
in your Android project. (See first example below.) Then use the "Manage NuGet Packages" menu item (available if you right-click your project's References) to find and install the necessary packages. Start withXamarin.Forms
, andMicrosoft.EntityFrameworkCore.Sqlite
for EF Core. The package manager, by default, pulls in the package you ask for, and the packages that it in turn depends on. If you open yourpackages.config
after installing packages, you'll see that's where they end up. (See second example below.)Here's what a valid but empty
packages.config
file looks like:After you install some packages, it will look something like:
How can you say this works I am trying to get data annotations to work in the standard way and it doesnt. I am using these in my dbcontext in my web api and I want to be transpose it from json to an object so doesnt xamrian still need the dataannotation to understand that in the form of.
My web api returns json so for example I have the following
[code]
Which I call using
[/code]
However cause xamrain forms doesn't understand data notations how can i keep my models the same for ef and for the Deserialize of the json to the .net object.
i use the following
[code]
public class JobsList
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; } // int
public int? EnginerId { get; set; } // int
public int? ClientId { get; set; } // int
public DateTime? StartTime { get; set; } // date
public DateTime? EndTime { get; set; } // date
[MaxLength]
public string Notes { get; set; } // nvarchar(max)
[MaxLength(150)]
public string photo { get; set; } // nvarchar(150)
public int? AssignedTo { get; set; } // int
public int? CompletedBy { get; set; } // int
public DateTime? CreatedDate { get; set; } // date
public DateTime? CompletedDate { get; set; } // date
public int? Components { get; set; } // int
public int? JobStatus { get; set; } // int
[/code]
But of course if i included a reference to this the xamrin form player will complain it doesnt like data annotations.
@ChrisWRea You're a true pioneer - thanks for putting this together. Question - now that this issue is closed - what needs to be updated? Or do you have plans to update your sample?
@MarkZhukovsky You're welcome. I was intending to revisit the sample when Entity Framework Core 2.1 is released. I'll remove any unnecessary workarounds then (i.e.
System.Runtime.CompilerServices.Unsafe
) that may have been required prior to VS 15.7.x.Good day sir Chris, How can I do this with an existing sqlite database? Also, where can I locate the local database created with the code used in this solution?
@christianquirante01 I haven't reverse-engineered a database with EF Core yet but this might be a good starting point: https://wildermuth.com/2017/12/20/Reverse-Engineering-Existing-Databases-in-Entity-Framework-Core-2. I expect one would do the reverse engineering work in a regular .NET Core project, and then consume the final model classes in the Xamarin project through a .NET Standard library.
As for where you can find the local database in the Todo sample, it will vary based on the platform. Look for the
FileHelper.cs
file within each platform project and there you'll see where the database path gets constructed. Here is the iOS app's FileHelper.cs: https://github.com/cwrea/XamarinTodo/blob/NETStd20_EFCore203/Todo.iOS/FileHelper.cs. You might modify yours to output the return value to debug output, so you can see the full path. On my Mac, I use a tool called iExplorer to grab copies of the SQLite database from the app's Library/Databases folder.As I stopped by this thread a few moments ago, I thought I would remark that I have tried to adapt the sample for Entity Framework Core 2.1 which came out a couple of weeks ago, but there remain issues preventing it from being compiled with Xamarin.iOS.
Anybody interested in following EF Core progress on Xamarin should check out these recent/open GitHub issues:
aspnet/EntityFrameworkCore - Add testing for Xamarin #8792 (open)
aspnet/EntityFrameworkCore - Xamarin requires linker hints to preserve APIs accessed via reflection #10963 (open)
xamarin/xamarin-macios - iOS app build fails when referencing package (e.g. Entity Framework Core 2.1) that depends on newer System.Memory #4168 (open)
xamarin/xamarin-android - Android app build fails when referencing package (e.g. Entity Framework Core 2.1) that depends on newer System.Memory #1769 (closed)
xamarin/xamarin-android - InvalidProgramException (invalid IL code), VerificationException, and SIGSEGV when executing LINQ queries simultaneously using thread pool #1483 (open)
xamarin/xamarin-macios - Xamarin.iOS linker removes assembly attributes, but large & useful libraries (e.g. EF Core 2.0) rely on such being preserved #3655 (open)
As for the ER Core adaptation of the XamarinTodo sample, the most recent published version is on EF Core 2.0.3: https://github.com/cwrea/XamarinTodo/tree/NETStd20_EFCore203. I removed some workarounds that are now unnecessary on Visual Studio 15.7.x. e.g. the projects now use package references instead of package.config.
Once I get a version successfully building and running on EF Core 2.1, I'll post an update here.
It has been confirmed that Azure Mobile Apps unfortunately will not support .NET Core, so the offline sync capability (that comes in their starter solution) with .net core backend is off the table.
Offline-first approach with bidirectional synchronization would really take this sample to the next level. Wondering if you've given this any thought? I was considering playing around with this free library for SQLite syncing to a SQL db on Azure. @ChrisWRea
Also, are you able to get this to work with the tooling for Migrations?
Hi Chris, Is your sample working now on EF Core SQLite 2.1 or are there still issues ?
@JohanMulder I can't say as I haven't had the time to try yet, assuming you are referring to having tried with the recent release of Visual Studio 15.8. Client work keeping me busy.
@ChrisWRea, VS 15.8.1 appears to fix the System.Memory compile error for iOS (github.com/xamarin/xamarin-macios/issues/4168) and I am able to deploy to a physical device, but I am still getting the AOT error related to Nullable columns.
When you circle back to this, I would be interested to know if you are seeing similar behavior, as the Nullable columns issue is marked as "Closed" in GitHub (github.com/aspnet/EntityFrameworkCore/issues/9249) and "RESOLVED FIXED" in the Xamarin Bugzilla (bugzilla.xamarin.com/show_bug.cgi?id=59184) and (bugzilla.xamarin.com/show_bug.cgi?id=58424).
Guys, what about migrations ? I know about the console app way and it works but it's a bit annoying.
That was cool. Thanks.
As I am starting a new project and face the decision which ORM (or DAL) to use, I stumbled upon this amazing thread.
Thanks @ChrisWRea.
I managed to integrate EF Core 3.1 into my project but I also got some exceptions while trying to do basic stuff.
Which make me wonder if EF Core is production ready at this point.
What have your experiences been so far, Xamarin Community? Thanks!
i wonder how is the performance on cascading and getting parent with children on multiple level.
For example, if you want to get a school object with all classes and all students as 3 layers. How fast it ist?
and if you delete a school object to cascade delete on all related classes and students.
Based on my experience sqlite-net was super slow. thats why i decided to use akavache which is based on sqlite as well but working asynchronous key value store.