question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scaffold generator generating incorrect attributes for composite FK associations and MSSQL schema-bound functions

See original GitHub issue

Describe 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:

  1. 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 (same nameof expression, even) as the corresponding components of ThisKey, even when the names do not correspond between the tables.  In other words, all components of both ThisKey and OtherKey apart from the first seem to be clobbered by duplicates of the first component of ThisKey.
  2. 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:closed
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Oct 21, 2022

Will be fixed next release. Currently we are busy with other stuff, so PR is welcome

0reactions
MaceWinducommented, May 17, 2023

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found