使用对象数据源时的父子关系
我正在使用我编写的类生成器,它为数据库中的每个表生成一个类,其中每个表字段作为属性等。 在此之前,我曾经向项目添加一个类型化数据集并向其中添加一些表。它自动检测表之间的关系,当我添加父表作为数据网格的数据源时,我可以添加另一个数据网格并使用其绑定源的前键数据成员来填充它,当有人将焦点移到父数据网格上时,子数据网格中的数据会相应改变。 现在我有了我的类,我添加一个对象作为我的 2 个数据网格的数据源,但显然它没有检测到父子关系。但如果我可以在对象数据源中拥有外键关系,那确实会有帮助。 有没有办法在对象数据源中建立这种关系?
I am experiencing with a class generator I've written, which generates a class for each table in database with each table field as a property and such.
Before that, I used to add a typed dataset to the project and add some tables to it. It automatically detected the relationship between tables and when I added a parent table as data source of a datagrid, I could add another datagrid and use the foreing key data member of it's bindingsource to fill it, and when someone moved the focus on parent datagrid, the data in child datagrid would change accordingly.
Now that I have my classes, I add an object as data source for my 2 datagrids, but obviously it doesn't detect a parent child relation. But It'd really help if I could have that foreign key relation in my object datasources.
Is there any way to have that relation in object datasource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 LINQ ORM,您的外键关系将自动反映在生成的模型中。
有关详细信息,请参阅 http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx。
如果您使用 ADO.Net,您可能会忘记勾选“在模型中包含外键列”选项。在 ADO 向导中,但不用担心(我们都经历过,众所周知,复选框很容易被忽视;)),您只需重新生成模型(重新运行向导),但一定要复制-粘贴您添加到文本文件或其他文件中的任何自定义代码,这样您就不会丢失它。祝你好运!
If you use LINQ ORM, your foreign key relationships are reflected automatically in your generated model.
Take a look at http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx for more info.
In case you use ADO.Net, there might be a chance you forgot to tick the choice "Include Foreign Key Columns in the Model." in the ADO wizard but no worries (we've all been there, tick boxes are notoriously easy to overlook ;) ), you'll simply have to re-generate the model (re-run the wizard) but be sure to copy-paste any custom code you've added to a text file or something, so you don't lose it. Good luck!