question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linq on DbSet throws missing method

See original GitHub issue

Using linq operations .single() and .where() seem to fail :

System.MissingMethodException: 'Method not found: 'System.Reflection.MethodInfo 

Version: Npgsql.EntityFrameworkCore.PostgreSQL Version=“2.2.0-preview1”

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    public class Blog
    {
        public Guid Id { get; set; }
    }
    public class BloggingContext : DbContext
    {
        private string connectionString = $"Host=localhost;Port=15432;Database=testDB;Username=postgres;Password=postgres";
        public BloggingContext()
        {
            Database.EnsureCreated();
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder
                .UseLazyLoadingProxies()
                .UseNpgsql(connectionString);
            base.OnConfiguring(optionsBuilder);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Blog>();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            using (var db = new BloggingContext())
            {
                Blog blog = new Blog();
                db.Set<Blog>().Add(blog);
                Blog contextBlog = null;
                contextBlog = db.Set<Blog>().Find(blog.Id); //OK
                contextBlog = db.Set<Blog>().SingleOrDefault(p => p.Id == blog.Id); //NOK
                List<Blog> test = db.Set<Blog>().Where(p => p.Id == blog.Id).ToList(); //NOK
            }
        }
    }
}

csproj

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.0-preview3-35497" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0-preview1" />
  </ItemGroup>

</Project>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jornvl90commented, Nov 27, 2018

Its my understanding that this is the expected behavior. Further, I’m pretty sure that behavior is defined in general for EF Core (i.e. the PostgreSQL provider isn’t driving it).

Thinking through it, you’ve basically got a partially completed operation happening here, and if those were to work, but then you disposed without saving, later queries would fail in a confusing way. That feels more inconsistent than the current behavior.

@roji Could you weigh in here?

It seems to be an EF decision indeed (https://stackoverflow.com/questions/699648/entity-framework-re-finding-objects-recently-added-to-context) But feels weird that .Find(id) does return the unsaved object and the others do not…

0reactions
austindrenskicommented, Nov 27, 2018

Great to hear, thanks for linking to that answer.

I’m going to close this since the initial issue is resolved. But feel free to continue posting if you have other questions or issues related to using the PostgreSQL provider.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MissingMethodException DbSet.ToList
This issue is dependency injection. MySql.Data.EntityFrameworkCore already depend on ef.core and probably installs another version of EF.Core.
Read more >
DBSet.Find() API missing in Entity Framework Core Final ...
Then, I landed in a really weird situation where in DBSet.Find() a piece is missing. This is a really crucial extension method for...
Read more >
DbSet<TEntity> Class (Microsoft.EntityFrameworkCore)
LINQ queries against a DbSet<TEntity> will be translated into queries ... this method throws an exception if there is more than one element...
Read more >
Null or empty object when LINQ to Entities query returns ...
Database queries return result sets. An empty set is a reasonable answer; it means you don't have any of the things searched for....
Read more >
Entity Framework Core 5 - Pitfalls To Avoid and Ideas to Try
In this post, we'll look at some pitfalls and ideas EF Core users like yourself may want to consider when developing an application....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found