Object Relational Mapping Issues: Suggestions needed

I've been trying to come up with a good design pattern for mapping data contained in relational databases to the business objects I've created but I keep hitting a wall. Consider the following tables: TYPE: typeid, description USER: userid, username, usertypeid->TYPE.typeid, imageid->IMAGE.imageid IMAGE: imageid, location, imagetypeid->TYPE.typeid I would like to gather all the information regarding a specific user. Creating a query for this isn't too difficult. SELECT u.*, ut.*, i.*, it.* FROM user u INNER JOIN type ut ON ut.typeid = u.usertypeid INNER JOIN image i ON i.imageid = u.imageid INNER JOIN type it ON it.typeid = i.imagetypeid WHERE u.userid = @userid The problem is that the field names collide and then I'm forced to alias every single field which gets out of hand very quickly. Does anyone have a decent design pattern for this kind of thing? I've thought about retrieving multiple results from a single stored procedure and then using a dataset to iterate through each one but I'm worried that some performance issues might bite me in the butt later. For example instead of the above query something like: SELECT u.*, t.* FROM user u INNER JOIN type t ON t.typeid = u.usertypeid WHERE u.userid = @userid; SELECT i.*, t.* FROM image i INNER JOIN type t ON t.typeid = i.imagetypeid INNER JOIN user u ON u.imageid = i.imageid WHERE u.userid = @userid; Does that seem like a decent solution? Can anyone foresee any issues with this approach?
latter solution seems bad, simply. Don't you think aliasing is a much better way to go. BTW, are you really using any ORM framework?

以上就是Object Relational Mapping Issues: Suggestions needed的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » WebStorm

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏