Skip to content
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

Association Property names #2803

Open
myabdolmaleki opened this issue Jan 28, 2021 · 5 comments
Open

Association Property names #2803

myabdolmaleki opened this issue Jan 28, 2021 · 5 comments

Comments

@myabdolmaleki
Copy link

hi

im using linq2db in my projects and its wonderful, but i have a question.

why it create property names like DeleteRecCarta22951Afds? but my Association Property Type is a List of DeleteRecordCatableFinancing class.

linq2db can generate association property name like "DeleteRecordCatableFinancings"?

thanks a lot

@viceroypenguin
Copy link
Contributor

Without seeing your schema or knowing which DB you're using, I'm not sure off the top of my head why it's generating that name for the FK link, but you can change it if you want. Open the .tt file you're using for generation and between the Load<dbtype>Metadata() call and the 'GenerateModel()' call, add this code:

		GetFK("<tablename>", "<db_fk_name>")
			.MemberName = "DeleteRecordCatableFinancings";

This will tell the generator to use the new name instead of the one it defaulted to based on the FK name. You can do this for each FK that you want to change names for.

@viceroypenguin
Copy link
Contributor

See here for more information on how to modify the generated code.

@sdanyliv
Copy link
Member

@myabdolmaleki, for such case we have introduced callback methods:
https://linq2db.github.io/articles/T4.html#configuring-generation-process

// Defines method to generate name for "one" side of association
Func<ForeignKey, string> GetAssociationExtensionSingularName
    = GetAssociationExtensionSingularNameDefault;
// Defines method to generate name for "many" side of association
Func<ForeignKey, string> GetAssociationExtensionPluralName
    = GetAssociationExtensionPluralNameDefault;

@myabdolmaleki
Copy link
Author

myabdolmaleki commented Jan 29, 2021

Hi

Im looking for automatic way(auto detect by linq2db) , these approaches you said are handy, my database is sql server.

I have to say "DeleteRecCarta22951Afds" is constraint name in sql server.

I want linq2db auto detect correct name for association property based on target property type, not based on constraints names in database like sql server, like entity framework.

Thanks

@sdanyliv
Copy link
Member

I don't get that. Many users have different naming conventions. So we have implemented callback mechanism to define exactly what is needed.

@viceroypenguin viceroypenguin changed the title Association Poperty names Association Property names Feb 3, 2021
@MaceWindu MaceWindu mentioned this issue Jul 5, 2021
34 tasks
@MaceWindu MaceWindu added the area: scaffold linq2db.cli label Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants