Scaffold generator generating incorrect attributes for composite FK associations and MSSQL schema-bound functions
See original GitHub issueDescribe your issue
A large number of tests started failing when we attempted to migrate our project from the old T4 template system to the new scaffold generator. Investigation of the cause revealed two errors in the attributes being generated by the scaffold generator:
- Associations generated from <var>n</var>-component composite foreign key constraints join on the first component <var>n</var> times (redundantly) and the other components never—furthermore, all components of
OtherKey
other than the first get set to the same name (samenameof
expression, even) as the corresponding components ofThisKey
, even when the names do not correspond between the tables. In other words, all components of bothThisKey
andOtherKey
apart from the first seem to be clobbered by duplicates of the first component ofThisKey
. - We have a schema-bound scalar function which we use from LINQ expressions. SQL Server appears to require it to be referenced with an explicit schema prefix (
dbo.
), which the scaffold was not including (unlike the old T4 system). Furthermore, the scaffold attribute was wrapping the name in[]
, resulting in[…](…)
syntax in the generated SQL, which was causing a syntax error on the SQL Server side.
Steps to reproduce
https://github.com/megaslice/LDBMinim
Environment details
Linq To DB
version: 4.2.0
Database (with version): SQL Server 2019
ADO.NET Provider (with version): Microsoft.Data.SqlClient 4.1.0
Operating system: Windows 10
.NET Version: 6.0
Issue Analytics
- State:
- Created a year ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Composite keys do not work properly when generating ...
It seems like EF6 has a lot of trouble with composite keys and keeps performing joins, inserts, and other operations on incorrect columns....
Read more >sitemap-questions-37.xml
... https://stackoverflow.com/questions/113655/is-there-a-function-in-python-to- ... /questions/137803/sql-server-select-statement-with-auto-generate-row-id ...
Read more >sitemap-questions-60.xml
... .com/questions/102535/what-can-you-use-generator-functions-for 2021-12-19 ... /5281974/code-first-independent-associations-vs-foreign-key-associations ...
Read more >Untitled
Adrian ramsay new zealand, Iis 6 set anonymous access, Association renaitre ... Sql server 2008 view index schema bound, Piriguete restaurant south gate, ......
Read more >Simple index
... flask-create contexter drf-channels odoo14-addon-website-sale-product-attribute-filter-category eventmonitoring-client semp sigfoxapi sitemap-generator ...
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
Will be fixed next release. Currently we are busy with other stuff, so PR is welcome
@alexmehlhorn. We are not able to reproduce it and I really don’t see from generator code how it could generate function name without escaping. Check that you have proper version instaled
dotnet tool list -g
and if it’s 5.2.0 - create new issue with function declaration script (no body needed, only signature) and your scaffold configuration