如何通过 WCF 使用 LinqToSql 维护子对象?
我目前正陷入这个解决方案的设计中。
数据层设计由以下部分组成:
- 配方(父高级对象)
- 语言详细信息(名称、语言描述)(很多)
- 标头(多个)
- 步骤(很多)
- 成分(多种)
- 数量(很多)
- 程序(很多)
- 注释(很多)
- 语言详细信息(名称、语言描述)(很多)
我面临的挑战是如何创建一个数据访问设计,在填充对象时在数据库中添加/删除子对象来自 WCF SaveRecipe(recipe) 方法?
这一切都源于管理层要求我们在应用程序中添加一个通信层,现在我们的 UI 耦合到我们的业务层,而 BL 直接耦合到 DAL,我们基本上需要在 BL 和 DAL 之间注入 WCF 。
我在 这个线程 中读到,使用 L2S 并不是 WCF 的好主意,但由于设计这并不新鲜,我们必须使用这种类型的方法,然后在我们可以重构大量 UI 工作后就放弃它。
I am currently stuck in the design of this solution.
The data layer design consists of the following:
- Recipe (parent high level object)
- Language Detail (name, description by language) (many)
- Headers (many)
- Steps (many)
- Ingredients (many)
- Quantities (many)
- Procedures (many)
- Notes (many)
- Language Detail (name, description by language) (many)
The challenge that I am having is how to create a data access design that will add/remove the child objects in the database when the object is populated from a WCF SaveRecipe(recipe) method?
This all stems from the management asking us to add a communications layer in our application, right now our UI is coupled to our business layer, and the BL is directly coupled to the DAL, we basically need the injection of WCF between the BL and DAL.
I have read in this thread that using L2S isn't a good idea over WCF, but since the design isn't new, we have to use this type of methodology, and then move away from it once we can refactor the heavy amounts of UI work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您尝试使用 WCF 发送内容,我建议您创建一个要在域中移动的数据的模型。 据我发现,您无法序列化 IQueryable 对象,但您可以创建一组由 Linq 填充的类,然后对其进行序列化。 例如:
然后用 WCF 填充该
列表,然后使用 WCF 发送列表就变得小菜一碟了。
If you are trying to send stuff down the line with WCF I suggest you create a model of the data you want to move around your domain. As far as I've found you can't serialize IQueryable objects, but you can create a set of classes that Linq populates and then serialize that. For example:
Then fill that up with
And then sending the list down the line with WCF becomes a piece of cake.
我喜欢 Karl 在您引用的 线程 上的回答:
看来您无论如何都必须重构 - 最好从在 UI 层中重构对 linq2sql 的依赖关系开始。
我认为您没有快速且简单的解决方案。
I like this answer from Karl on the thread you referenced:
It looks like you're going to have to refactor anyways - just as well start by refactoring out the dependency to linq2sql in your UI layer.
I don't think you have a quick and easy solution.
我不建议通过 WCF 公开 L2S 类。 创建 DataContract 对象的层次结构,并通过 WCF 传递它们。 这样做的缺点是您必须将 L2S 对象“深度复制”到 DataContract 层次结构中,但优点是您只能包含通过网络传输所必需且正确的字段。 例如,在我现在正在处理的一个项目中,我通过网络传递一个 EmployeeData 对象,其中包括我的大部分 L2S Employee 字段,但不包括员工的 salted 哈希和字段等内容。 密码盐。
I don't recommend exposing L2S classes over WCF. Create a hierarchy of DataContract objects, and pass those over WCF. The downside of this is that you have to "deep copy" your L2S objects into your DataContract hierarchy, but the upside is that you can only include fields that are necessary and proper for transport over a network. For example, in a project I'm working on now, I pass an EmployeeData object over the network that includes most of my L2S Employee fields but excludes things like the employee's salted hash & password salt.
创建包含和排除子条目的类也可能是一个想法。 我有时会创建这样的类:
编辑:在帖子完成之前无意中发布。
It could also be an idea to create classes both including and excluding child entries. I have sometimes created classes like this:
Edit: inadvertedly posted before the post was finished.