WCF RIA 服务/Linq-to-SQL:包含外部表中的属性

发布于 2024-10-05 20:07:09 字数 473 浏览 0 评论 0原文

假设您有以下相关表(商店 -> 类别 -> 产品

  • 商店
  • 类别
  • 产品

我想创建一个网格来编辑产品。使用 RIA 服务,这很简单。但是,如果我还想在我的 Products< 中显示 Stores 中的 StoreNameCategories 中的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想念有你 2024-10-12 20:07:09

你如何设置这个?您是绑定到 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.

陌路终见情 2024-10-12 20:07:09

最简单的方法是注释产品的元数据文件,并让网格为您生成列。

例如,您的表可能如下所示:

Product
    int Id; 
    string ProductName;
    int CategoryId;

Category
    int Id;
    string CategoryName;
    int StoreId;

Store
    int Id; 
    string StoreName;

现在,当您创建服务时,您可以包含域模型中的 3 个表/实体,并让它为您生成元数据文件。在该文件中,正确注释对象,如下所示:

internal sealed class ProductMetadata
{
    [Key]
    [Bindable(false)]
    [Display(AutogenerateField=false)]
    public int Id { get; set; }

    [Bindable(true, BindingDirection.TwoWay)]
    [Display(Name="Product")]
    [StringLength(20, MinimumLength=3)]
    public string ProductName { get; set; }

    [Bindable(false)]
    [Display(AuteogenerateField=false)]
    public Category Category { get; set; }

    [Required]
    [Bindable(false)]
    [Display(AutogenerateField=false)]
    public CategoryId { get; set; }
}

您可以对其他对象的元数据执行相同的操作。

您可能需要做的唯一另一件事是向网格中添加另外 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:

Product
    int Id; 
    string ProductName;
    int CategoryId;

Category
    int Id;
    string CategoryName;
    int StoreId;

Store
    int Id; 
    string StoreName;

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:

internal sealed class ProductMetadata
{
    [Key]
    [Bindable(false)]
    [Display(AutogenerateField=false)]
    public int Id { get; set; }

    [Bindable(true, BindingDirection.TwoWay)]
    [Display(Name="Product")]
    [StringLength(20, MinimumLength=3)]
    public string ProductName { get; set; }

    [Bindable(false)]
    [Display(AuteogenerateField=false)]
    public Category Category { get; set; }

    [Required]
    [Bindable(false)]
    [Display(AutogenerateField=false)]
    public CategoryId { get; set; }
}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文