Closed rwil02 closed 4 years ago
OK, after painstakingly filtering the tables, I narrowed it down to two, and then to the foreign key between them
ALTER TABLE [dbo].[BatchHeader] WITH NOCHECK ADD CONSTRAINT [FK_BatchHeader_ProductionRun] FOREIGN KEY([ProdRunID], [ProductCode]) REFERENCES [dbo].[ProductionRun] ([ProductionRunID], [ProductCode]) GO
So I'm assuming a multiple field foreign key is the problem
From the stack trace it's getting a null reference while checking the relationship to see if it's a many to many. Do both of the tables involved in the Many To Many exist in sql server? Do you have a bad constraint?
Also, I'd highly recommend using the following templates: https://github.com/loresoft/PLINQO.EntityFrameworkCore which target the latest versions of .NET Core :)
I can limit to exactly these two tables and get the error. Dropping the foreign key removes the error. Adding it back restores the error. And yes, they exist since they are generating from the database.
My assumption is that the 2 field foreign key causes "ManyToMany" to exist with a result, but that "IntermediateAssociation" is null.
I'd restructure public static bool IsParentManyToMany(this IEntity entity) { if (entity.GetAssociations(AssociationType.ManyToMany).Count == 1) { return entity.GetAssociations(AssociationType.ManyToMany).First().IntermediaryAssociation.IsParentEntity; } return false; } as something like: public static bool IsParentManyToMany(this IEntity entity) { var assocs = entity.GetAssociations(AssociationType.ManyToMany); //List if(null == assocs) { return false; //or throw and mention name of entity } if (assocs.Count != 1) { return false; } var assoc = assocs.First(); if(null == assoc.IntermediaryAssociation) { return false; //or throw mentioning name of entity and name of association } return assoc.IntermediaryAssociation.IsParentEntity; }
Can I use https://github.com/loresoft/PLINQO.EntityFrameworkCore in framework 4.6 (not 4.6.1)? That's my current deployment constraint.
Here you go. I found the source files too, so I might have a play if I get time. test_efdb.zip
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
I have a fairly complex database (~200 tables) Running the standard MS EF generation via command line "seems" to work (I get CSDL and SSDL files) When I try running PLINQO-EF against the same database, the EDMX generation fails. Then the Entities and Queries templates produce nothing (I assume as a result of the EDMX failing)
The EDMX generation fails with: Entities.csp(0,0) Object reference not set to an instance of an object. Stack Trace: at Generator.Microsoft.Frameworks.Extensions.IsParentManyToMany(IEntity entity) at Generator.Microsoft.Frameworks.EdmxGenerator.MergeMappingModel(IEnumerable
1 entities) at Generator.Microsoft.Frameworks.EdmxGenerator.Create(IEnumerable
1 entities) at _CodeSmith.edmx_cst.Generate() in E:\Temp\PLINQO EF\MillDB\Templates\CSharp\edmx.cst:line 112 at _CodeSmith.edmx_cst.__RenderMethod1(TextWriter writer, Control control) in E:\Temp\PLINQO EF\MillDB\Templates\CSharp\edmx.cst:line 163edmx.cst:line 112 is:
EdmxGenerator generator = new EdmxGenerator(settings); var provider = new SchemaExplorerEntityProvider(SourceDatabase); EntityManager manager = new EntityManager(provider); generator.Create(manager.Entities);
And the "Generator.Microsoft.Frameworks.Extensions" method with the error is: public static bool IsParentManyToMany(this IEntity entity) { if (entity.GetAssociations(AssociationType.ManyToMany).Count == 1) { return entity.GetAssociations(AssociationType.ManyToMany).First().IntermediaryAssociation.IsParentEntity; } return false; }
Problem is, the error doesn't tell you the Entity involved, so there's no way of finding out where I need to "fix" things. The DLL says copyright Microsoft, but I can't find a place to raise this anywhere.