Comments (5)
Yes, you might open an issue there (if there isn't one already).
from specification.
The first thing to check is if you can make the query work directly with your dBcontext. Apply your LINQ to dBContext.Players and see if you can get it to work. If not, the problem isn't related to this Specification package.
from specification.
Hi @mcchessers-sp,
Unfortunately, it has nothing to do with this library. We're passing the expression as it is. I suspect the MySQL provider doesn't know how to translate the filtered include which contains Take
.
You may try to test without specifications, working directly with DbContext.
from specification.
Here I created a full test app using SqlServer
provider. It works as expected. Try the same code with MySql
provider.
using Ardalis.Specification;
using Ardalis.Specification.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
await AppDbContext.SeedAsync();
using var dbContext = new AppDbContext();
var repo = new Repository<Customer>(dbContext);
var spec = new CustomerSpec();
var customer = await repo.FirstOrDefaultAsync(spec);
Console.WriteLine($"We fetched {customer!.Addresses.Count} addresses!");
public class CustomerSpec : Specification<Customer>
{
public CustomerSpec()
{
Query.Include(x => x.Addresses.Take(2));
}
}
public interface IRepository<T> : IRepositoryBase<T> where T : class
{
}
public class Repository<T> : RepositoryBase<T>, IRepository<T> where T : class
{
public Repository(AppDbContext dbContext) : base(dbContext)
{
}
}
public record Address
{
public int Id { get; set; }
public int CustomerId { get; set; }
}
public record Customer
{
public int Id { get; set; }
public List<Address> Addresses { get; set; } = new();
}
public class AppDbContext : DbContext
{
public DbSet<Customer> Customers => Set<Customer>();
public DbSet<Address> Addresses => Set<Address>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=IncludeTest;Integrated Security=SSPI;ConnectRetryCount=0;";
optionsBuilder.UseSqlServer(connectionString).LogTo(Console.WriteLine);
}
public static async Task SeedAsync()
{
using var dbContext = new AppDbContext();
await dbContext.Database.EnsureDeletedAsync();
await dbContext.Database.EnsureCreatedAsync();
var customer = new Customer
{
Addresses = new List<Address>()
{
new Address(),
new Address(),
new Address()
}
};
dbContext.Customers.AddRange(customer);
await dbContext.SaveChangesAsync();
}
}
from specification.
Thank you for the suggestions. I tried using DbContext outwith the specification:
DbContext.Players.Where(p => p.Id == (int)TestPlayers[0].Id).Include(p => p.ActiveDays.Take(1));
.. and got the same error, which would suggest that perhaps the driver (Pomelo) may be at fault?
from specification.
Related Issues (20)
- Remove obsolete API
- Update pipelines.
- Including nullable/optional navigation property causes only non-nullable connected objects to be returned HOT 3
- Refactor and improve integration test fixtures.
- Why do the Update and Delete not returning anything? HOT 3
- Logging in the Package HOT 4
- Feature Request: Deletion of entities via specification HOT 5
- Shadow properties HOT 4
- Query to return anonymous type HOT 4
- Question: Can I some how join table "B" when my entity T does not have a navigation property to "B" ? HOT 2
- Expression Evaluation HOT 8
- Simplify Cache usage HOT 5
- DbSet<T>.WithSpecification together with ISpecification<T, TDestination> throws SelectorNotFoundException HOT 4
- Conceptual question about the ORM specific implementations HOT 2
- Is it possible to use generic repository approach like this? HOT 1
- Specification - Include with Where clause HOT 1
- Strange behavior when compare DateTime HOT 3
- Apply Distinct in specification query HOT 1
- How to combine specifications? HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from specification.