Linq on DbSet throws missing method
See original GitHub issueUsing 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:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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…
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.