在存储过程上使用 LINQ to SQL 的一对多和一对一关系
假设我有三个表 Customer(ID,Name),CustomerAddress(ID,Address1,Address2),Phone(ID,PhoneNumber)。因此,在此情况下,每个客户都有多个地址(一对多关系),每个地址有一个电话(一对一关系)。我有一个存储过程,它按以下顺序返回所有数据
ID Name Address PhoneNumber
1001 John MD 1234
1001 John VA 1231
1001 John WA 1232
1002 Mary NJ 0231
1002 Mary NY 0232
1002 Mary OR 0032
现在,在获取上述数据后,我坐在 foreach 循环中并填充我的数据对象。但是,我想使用 LINQ-SQL 动态填充这些数据对象。我看到这篇文章完全做了同样的事情http://www.codeproject.com/KB/linq/OneManyandOneOneLINQ.aspx?fid=1543095&select=3878390&fr=1& ;df=90&mpp=25&noise=3&sort=Position&view=Quick。 唯一的区别是我正在运行存储过程来获取数据。 那么,有人知道如何用存储过程填充这些实体类吗? 任何输入都会真正有帮助。
Lets say I had Three tables Customer(ID,Name),CustomerAddress(ID,Address1,Address2),Phone(ID,PhoneNumber). So in this,Each Customer has Multiple Addresses(one-Many relation ship) and Each Address has one Phone (one-one relation ship). I had a stored procedure which returns all the data in below order
ID Name Address PhoneNumber
1001 John MD 1234
1001 John VA 1231
1001 John WA 1232
1002 Mary NJ 0231
1002 Mary NY 0232
1002 Mary OR 0032
Right now, after getting above data i am sitting in a for each loop and filling my data objects.But, I want fill those Data objects dynamically using LINQ-SQL. I saw this article which exactly does the same thing http://www.codeproject.com/KB/linq/OneManyandOneOneLINQ.aspx?fid=1543095&select=3878390&fr=1&df=90&mpp=25&noise=3&sort=Position&view=Quick.
The only difference is i am running stored procedure to get data.
So, Any one knows hoe to fill these entity classes w/ stored procedure?
Any input would be really help full.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论