-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Weird behaviour in Select using LINQ #24118
Comments
@boppercr can you please submit a minimal code sample that demonstrates exactly what you're trying to do, and the exact exception and/or incorrect behavior that you're seeing? That's really the easiest way to get your scenario across. Aside from that, 2.2 is out of support - please try your scenario with 3.1 (which fixes a lot of issues). |
Alright. We have an update planned soon to get straight through to 5, so we'll see there. There's no real problems remaining, but I was curious still. Here's what I can provide : using (var dc = new Database.DatabaseService())
{
var decl = dc.Declaration.Where(d => d.IdDeclaration == IdDeclaration).Select(d => new Database.DroitAuteur.Declaration()
{
//_Shortened for brevety_
DateCreation = DateTime.Now,
IdTypeOuvrage = d.IdTypeOuvrage,
IdTypeSupport = d.IdTypeSupport,
AnneeSession = d.AnneeSession,
IdCours = d.IdCours,
IdEmployeEffectuePour = d.IdEmployeEffectuePour,
Reference = d.Reference,
DeclarationInformation = new Database.DroitAuteur.DeclarationInformation(), //Here's where the issue happens.
DeclarationDoc = d.DeclarationDoc.Select(doc => new Database.DroitAuteur.DeclarationDoc()
{
Annee = doc.Annee,
Auteur = doc.Auteur,
//_Shortened for brevety_
}).ToList(),
}).FirstOrDefault();
if (decl == null) return (false, null);
dc.Add(decl);
dc.SaveChanges();
return (true, decl.IdDeclaration);
} In example, the "DeclarationInformation" class has a couple of properties which include the navigation ones. There's "IdDeclarationInformation" that is the Primary Key and "IdDeclaration" that is a Foreign Key with a Unique Constraint on it that links it to "Declaration". At first, theses 2 values are default(int)|0 and the second time it happens, the values are the ones that were generated when the "SaveChanges" function was called. Example : |
Duplicate of #7983 |
My colleague and I encountered a weird "bug" if you will while using EF Core and while we're not sure if it's a bug or a use case that shouldn't be happening, I felt like it needed to be asked here.
Here's a little summary :
We have a goal to duplicate part of a record of table X and all that follows. This includes an empty record of Y. We do this by fetching the data we want duplicated in from the X table with the corresponding ID and using a Select, we create a new record of X with some of the old values and some new.
The issue comes when trying to add a new record of Y. We do something like this :
The first time, everything is good and works fine. The issue raises when we try another time to duplicate the same record again. The
new Y()
will contain the values of the previous one we created, even though it's a new object. This issue won't happen if we create the Y object outside of the Select request.Anyone has an idea what could be happening here?
I know it's fairly weird/complicated, but I'll try to answer all the questions to the best of my knowledge.
EF Core version: 2.2.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: e.g. .NET 2.2
Operating system: Windows 10
IDE: Visual Studio 2017 15.9.27
The text was updated successfully, but these errors were encountered: