实体框架:从相关的级联表创建单个实体
我正在使用一个数据库,其中包含用于存储人员地址详细信息的相关表。下表存储信息 – 县、城市郊区、地址和地址类型。
除了AddressTypeId(与AddressType 表关联)之外,Address 表还保存街道和门牌号信息。 Address 表还有一个 SuburbId 列,用于与 Suburb 表关联。个人地址的关联级联到县表。
我希望 Person 数据对象具有 IList 属性。实现这一目标的最佳方法是什么?
- 使用存储过程在实体设计器上生成地址实体。
- 创建一个复杂类型并将其作为 IList 添加到 Person 类型。
除了上述选项之外,可能还有其他推荐方法。如果有人可以向我指出一个分步示例,那就太好了。
I am working with a database contains related tables for storing person address details. The following tables store the information – County, City Suburb, Address and Address Type.
The Address table holds street and house number information in addition to AddressTypeId (Associated to AddressType Table). The Address table also has a SuburbId column for the association with the Suburb table. The associations of a person’s address cascade down to the County table.
I want the Person data object to have an IList property. What would be my best approach to achieve this?
- Use a stored procedure to generate the Address entity on the Entity designer.
- Create a complex type and add this to the Person type as IList.
There might be some other recommended way than the above options. If there is a step-by-step example some one could point me to, that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就您的问题而言,您可以编写一个存储过程来获取所有地址信息。在存储过程末尾有一个 select 语句,用于选择所有地址信息。
当您添加此过程实体框架(我假设是 4.0)...您可以创建一个函数导入,并且 ef4 将创建一个复杂类型以返回您的存储过程。这是 教程。
As far your question you can write a stored procedure that gets all the address information. Have a select statement at the end of your stored procedure selecting all of the address information.
When you add this procedure entity framework(4.0 I assume)...you can create a function import and ef4 will create an complex type for return of your stored procedure. Here is a tutorial.