Reputation: 1133
I tend to create tables in a database then drag them onto the dbml designer to create my DataContext. I usually create the associations in the dbml manually, should I be doing this, or should I have those associations in the database already? I ask, because in the MySQL world, these associations would have been represented by foreign keys, and I feel like I am bypassing that at the database level.
Upvotes: 2
Views: 1788
Reputation: 72920
You're safer creating the foreign keys in MySQL. Your .NET code will honour these associations if they're in the DBML only, but there won't be anything at the database level to enforce the same constraints if you don't create them, meaning direct DB SQL access could be dangerous.
Upvotes: 1
Reputation: 14119
I recommend creating the foreign keys just as you do in MySQL. The designer will pick them up.
My approach when doing linq2sql is that I let the designer give as much information as possible and let it generate the whole dbml again when there is a change.
I store customization in a sperate partial C# class. Why? I'm more assured that the db schema and dbml are in sync so I can reason from the same model and not take into account any hand made customization to the dbml. It's good that you cab edit the dbml directly though since it will help you diagnose problems better.
Upvotes: 1