Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS2019 + UWP + EF v 3.1.1 Broken #19978

Closed
Noemata opened this issue Feb 19, 2020 · 6 comments
Closed

VS2019 + UWP + EF v 3.1.1 Broken #19978

Noemata opened this issue Feb 19, 2020 · 6 comments

Comments

@Noemata
Copy link

Noemata commented Feb 19, 2020

(1) First with the broken docs.

You cannot have a UWP project as part of your solution when performing a migration from the nuget console in VS2019. So I set the .Net Standard Model project as the default and unloaded the UWP part.

Results:

PM> Add-Migration InitialCreate
Build started...
Build succeeded.
To undo this action, use Remove-Migration.

Then I edited the project file so I had this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.0;netstandard2.0</TargetFrameworks>
    <RootNamespace>EFGetStarted.UWP</RootNamespace>
    <AssemblyName>EFGetStarted.UWP.Model</AssemblyName>
  </PropertyGroup>
  <PropertyGroup>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
  </PropertyGroup>
  <ItemGroup>
    <!--<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.9" />-->
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <Reference Include="Windows">
      <HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
      <IsWinMDFile>true</IsWinMDFile>
    </Reference>
  </ItemGroup>
  
</Project>

Changed my DB context code so it looks like this:

using System;
using System.IO;
using System.Net;
using Microsoft.EntityFrameworkCore;
using Windows.Storage;


namespace EFGetStarted.UWP
{
    public class SQLiteDbContext: DbContext
    {
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            //optionsBuilder.UseSqlite("Filename=AppData.db");
            var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "AppData.db");
            optionsBuilder.UseSqlite($"Filename={dbPath}");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Make Id required.
            modelBuilder.Entity<Blog>()
                .Property(p => p.BlogId)
                .IsRequired();

            // Make Id required.
            modelBuilder.Entity<Post>()
                .Property(p => p.PostId)
                .IsRequired();
        }
    }
}

(2) Next, the broken implementation (note, this was derived from documented examples)

In my UWP application, I get an exception at the "ToList()" line of code below:

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            using (var db = new SQLiteDbContext())
            {
                var blogs = db.Blogs;

                Blogs.ItemsSource = db.Blogs.ToList();
            }
        }

The exception being:

'SQLite Error 1: 'no such table: Blogs'.'

Because there are no tables in the DB. If I copy in a DB from a previous EF release (way back), it works.

Why is this broken? Given how much the docs are out of touch, treasure hunting for a solution is not fun given how obscure some of these details are. Please fix docs and the lib.

Steps to reproduce

Further technical details

EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.3)

@Noemata
Copy link
Author

Noemata commented Feb 19, 2020

I was able to get to a working state with UWP, provided I used the command line tooling. Looks like the issue is with the nuget console part of the migration process.

Please update the docs for UWP.

@ajcvickers
Copy link
Member

@Noemata We acknowledge that the experience with UWP is not very good at the moment. We are looking into improving the experience for various U.I frameworks as part of the EF Core 5.0. However, there are a lot of different U.I. frameworks that EF Core can be used with so we may not prioritize them all for 5.0.

We also need to improve the existing documentation and links: see dotnet/EntityFramework.Docs#1838

Some comments on your specific points:

@Noemata
Copy link
Author

Noemata commented Feb 23, 2020

@ajcvickers, your remarks are disappointing. "Various UI frameworks..." begs the question, "What is the Microsoft endorsed native UI framework for Windows 10?" Even as little as a year ago, Microsoft was still singing the praises of UWP. That has come to a dramatic halt. What now, DirectX + C++? WPF? Are we really doing a repeat of the Silverlight saga? As for EF 3.1.1 + UWP; it works and works well provided you can get past the invalid state of available documentation. I don't know what to say anymore. Renaming UWP to WinUI is not the answer, nor welcome.

@ajcvickers
Copy link
Member

@Noemata I agree that this is not at all clear. As soon as I can give you a more definite answer from the EF side, then I will do so. Right now there is, unfortunately, nothing else I can say. You would be probably be better off reaching out to the Windows/UWP teams directly. It's unlikely anything posted here will be seen by the right people, since EF is only a small part of the wider picture.

@Noemata
Copy link
Author

Noemata commented Feb 25, 2020

WinUI and by extension UWP is now at the bottom of the heap when Microsoft enumerates UI options. Such de-emphasis doesn't go unnoticed. It's also painfully obvious Xamarin is now somehow a place holder for UWP (do a search for UWP on channel 9, results return Xamarin). Yet WindowsX runs Win32 (WPF/Winforms/GDI) in a security sandbox and will likely break many applications. Only UWP runs against OS APIs directly, consequently has much better performance on the new OS. It's a very confused message for those looking for the best way forward. Microsoft needs to sort out its messaging in a hurry. UWP has the .Native compiler. It's a big deal if you opted to use C# as a core element of your tooling because it can't easily be reverse engineered, and you have the prospect of an improving performance story as the compiler evolves.

@ajcvickers
Copy link
Member

Closing as duplicates of the issues referenced above. Unfortunately, I am not able to comment more generally about UWP.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants