Asked by:
Home

Question
-
Hi,
i want to ask regarding Entityframework 6.0 code first foreign key naming convention
i had created the model but i found in the database all the foreign key names follow this conventions
FK_dbo.firstTable_dbo.secondTable_column, also in Primary key naming follow something like this PK_dbo.TableName.
i don't want to see this dbo. in any constraint at all, i want to change this convention.
i found this but i failed to change the naming convention, so is there any help?
https://msdn.microsoft.com/en-us/data/dn469439
Thanks
http://fromisraeltolebanon.info
- Moved by Fei Hu Wednesday, December 27, 2017 1:36 AM From C# forum
Tuesday, December 26, 2017 7:55 PM
All replies
-
Do you know what DBO means, its purpose, in MS SQL Sever database table schemas? Do you have basics MS SQL Server administration skills to know to leave the DBO alone? Why are you not using MSMS to make the change, if possible which I doubt or even do it?
EF code first always leads the developer without basic DB Administration skills to trouble, IMO.
Anyway, you can post to he forum?
http://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework
Tuesday, December 26, 2017 10:47 PM -
Hi Haitham,
Your question is more related to Entity Framework, I will move the thread to ADO.NET Entity Framework and LINQ to Entities for suitable support.
The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools . If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.
Best Regards,
Neil Hu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Wednesday, December 27, 2017 1:34 AM -
Hi Haitham Khattab,
According to your description and related link, I create a demo, but it could not change the constraint name. As a workaround, you could modify the migration file by manually before you update-database. like this:
CreateTable( "dbo.Posts", c => new { PostId = c.Int(nullable: false, identity: true), Title = c.String(), Content = c.String(), BlogId = c.Int(nullable: false), }) .PrimaryKey(t => t.PostId) .ForeignKey("dbo.Blogs", t => t.BlogId, cascadeDelete: true, name: "FK_NameAsYourWant") .Index(t => t.BlogId);
If you use entity framework core, you could use HasConstraintName to achieve it, like this:
modelBuilder.Entity<Post>() .HasOne(p => p.Blog) .WithMany(b => b.Posts) .HasForeignKey(p => p.BlogId) .HasConstraintName("ForeignKey_Post_Blog");
https://ef.readthedocs.io/en/staging/modeling/relational/fk-constraints.html
Best regards,
Zhanglong Wu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Wednesday, December 27, 2017 8:08 AM -
may be you don't understand what i want?
i don't care what all about this dbo
in my case i don't want to see it in the constraint name , its just trash and has no sense causing a trouble
which why i want to get ride of it
Haitham Khattab
http://fromisraeltolebanon.info
Wednesday, December 27, 2017 7:34 PM -
Hi Neil
thanks alot
http://fromisraeltolebanon.info
Wednesday, December 27, 2017 7:34 PM -
may be you don't understand what i want?
i don't care what all about this dbo
in my case i don't want to see it in the constraint name , its just trash and has no sense causing a trouble
which why i want to get ride of it
Haitham Khattab
http://fromisraeltolebanon.info
it's kind of a worthless endeavor of no value. You should abandon it.
Wednesday, December 27, 2017 11:37 PM