WCF RIA 服务/Linq-to-SQL:包含外部表中的属性
假设您有以下相关表(商店 -> 类别 -> 产品
)
- 商店
- 类别
- 产品
我想创建一个网格来编辑产品
。使用 RIA 服务,这很简单。但是,如果我还想在我的 Products< 中显示
Stores
中的 StoreName
和 Categories
中的 CategoryName
该怎么办? /代码> 列表?额外的两列应该是只读的。
如何实施?
更新:我正在尝试以最简单的形式做到这一点。那不是 ViewModel,只有拖放,代码(如果有)将放在代码隐藏中。我正在使用 Ling2Sql 并返回 GetProducts 查询的默认实现。
问候
拉尔西
Say you have the following related tables (Stores -> Categories -> Products
)
- Stores
- Categories
- Products
And I want to create a grid to edit Products
. This is straightforward with RIA Services. But what if I also want to show StoreName
from Stores
and CategoryName
from Categories
in my Products
list? The two extra columns should be readonly.
How can this be implemented?
Update: I'm trying to do this in it's simplest form. That is no ViewModel, only drag'n drop, code (if any) will go in codebehind. I'm using Ling2Sql and returning the default implementation for the GetProducts query.
Regards
Larsi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你如何设置这个?您是绑定到 ViewModel 还是仅使用后面的代码? Web 服务是否正在发回 Product LINQ 对象列表,或者您是否正在执行其他操作?
有多种选择,但这实际上取决于您想要做什么。
How do you have this set up? Are you binding to a ViewModel or just using the code behind? Is the web service sending back a list of Product LINQ object or are you doing something else?
There are a variety of options but it really depends on what you're trying to do.
最简单的方法是注释产品的元数据文件,并让网格为您生成列。
例如,您的表可能如下所示:
现在,当您创建服务时,您可以包含域模型中的 3 个表/实体,并让它为您生成元数据文件。在该文件中,正确注释对象,如下所示:
您可以对其他对象的元数据执行相同的操作。
您可能需要做的唯一另一件事是向网格中添加另外 2 列,并将它们映射到 Product.Category.CategoryName 和 Product.Category.Store.StoreName
The simplest way to do it is to annotate your metadata file for the products and let the grid generate the columns for you.
For instance, your tables will probably look something like this:
Now, when you create your service, you can include the 3 tables/entities from your domain model and have it generate the metadata file for you. In that file, annotate the objects correctly like so:
You can do the same to your other objects' metadata.
The only other thing you might have to do is add 2 other columns to your grid, and have them map to Product.Category.CategoryName and Product.Category.Store.StoreName