如何将表包装成更通用的类以与多个数据上下文一起使用?
我有两个不同的 DataContext(SQL 数据库),它们具有相同的数据,只是命名略有不同:
DB1: Serialnumber Productnumber DB2: SerialNumber ProductNumber 结果
因此,我希望能够将这些表包装在一个类中,该类可以让我取回序列号和产品号,而不管它来自哪个 DataContext。我研究过 DataTableMappings,但我真的不知道从哪里开始。我还希望它能够通过 LINQ 和直接 SQL 查询来工作。同样,我希望它尽可能通用,这样我就可以对两个不同的上下文使用相同的 LINQ 查询。我在寻找什么?
I have two different DataContexts (SQL Databases) that have the same data, just with slightly different naming:
DB1: Serialnumber Productnumber
DB2: SerialNumber ProductNumber Result
So I want to be able to wrap these tables in a class that will let me get back the serial number and product number regardless of the DataContext that it is coming from. I've looked into DataTableMappings, but I really have no idea where to begin. I'd also like this to work via LINQ and direct SQL queries. Again, I'd like it to be as generic as possible so I can use the same LINQ queries for the two different contexts. What is it that I am looking for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您可能需要考虑针对业务逻辑的接口进行编码 - 这样您就可以传入 DB1 或 DB2 对象,只要它们的类实现指定的接口即可。
As a start, you'd probably want to consider coding against interfaces with your business logic - that way you can pass in DB1 or DB2 objects as long as their classes implement the interfaces specified.