【问题标题】:Client Side Partial For DevForce Entity cannot see Properties exposed in the models partialDevForce 实体的客户端部分无法看到模型部分中公开的属性
【发布时间】:2017-06-02 18:35:08
【问题描述】:

我目前正面临一个问题,我正在尝试为我们的 Model First DevForce 实体之一制作 WPF 客户端部分。问题是 WPF 客户端中的部分似乎无法访问客户端项目引用的模型项目中其兄弟部分中的属性。

我在客户端和模型中都使用了相同的命名空间,但客户端不断返回,因为它是只有一个文件的部分。

我这样做的主要原因是我需要访问驻留在我的客户端项目中的静态类的属性,该属性位于我添加到客户端实体 Partial 的属性中。以下是其中的一个样本:

模特好友班:

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Principal;
using IbEm = IdeaBlade.EntityModel;
using IdeaBlade.EntityModel.Security;
using IdeaBlade.Validation;

// ReSharper disable CheckNamespace
namespace BearPaw.Models.Main
{
[MetadataType(typeof(NavigationButtonGroupMetadata))]
public partial class NavigationButtonGroup
{

    [IbEm.AllowRpc]
    public static object NameAlreadyInUse(IPrincipal principal,
      IbEm.EntityManager entityManager, params Object[] args)
    {
        string buttonGroupNameToCheck = (string)args[0];

        var serverButtonGroup = entityManager.GetQuery<NavigationButtonGroup>().FirstOrDefault((u) => u.Name == buttonGroupNameToCheck);

        return serverButtonGroup != null;
    }

}

public class NavigationButtonGroupMetadata
{
    [RegexVerifier("Name", @"^[A-Za-z_]*$")]
    [StringLengthVerifier(MaxValue = 100, IsRequired = true, ErrorMessage = "Button Group Name must be unique")]
    public static string Name;
}

}

客户端部分:

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Principal;
using IbEm = IdeaBlade.EntityModel;
using IdeaBlade.EntityModel.Security;
using IdeaBlade.Validation;

// ReSharper disable CheckNamespace
namespace BearPaw.Models.Main
{
[MetadataType(typeof(NavigationButtonGroupMetadata))]
public partial class NavigationButtonGroup
{
    public bool IsEnabled
    {
        get
        {
            {
                if (NavigationButtonGroupType.AlwaysVisible || (DynamicMenuItemsHelper.MenuDetails != null && DynamicMenuItemsHelper.MenuDetails.Count() > 0 )) return true;
                var currentUser = Authenticator.Instance?.DefaultAuthenticationContext?.Principal?.Identity;
                return currentUser != null && NavigationButtons.
                    Any(b => b.IsEnabled);
            }
        }
    }
}
}

Visual Studio 在 NavigationButtonGroupType.AlwaysVisible 上显示编译错误,说明非静态字段需要对象引用,即使 NavigationButtonGroupType 是模型中实体上的导航道具。类似的问题适用于 NavigationButtons 也是一个 nav 属性,但 Visual Studio 声明它在当前上下文中不存在。

任何关于为什么这不起作用的帮助或指示将不胜感激。

非常感谢

【问题讨论】:

    标签: c# wpf devforce


    【解决方案1】:

    部分类定义允许您将类定义分布在多个文件中,但只能在同一个程序集中。这是 C# 的事情,而不是 DevForce 限制。请参阅here 了解更多信息。

    如果我的理解正确,您希望实体类的某些功能仅在客户端可用(还有一些在服务器上可用?)。如果您正在定义客户端和服务器模型项目,您可以使用条件编译来确定实体的哪些功能在每个程序集中可用。这在 DevForce SL 应用程序中是相当标准的,尽管在 WPF 中可能较少使用。

    如果您使用这种类型的架构,另一种选择是将此类属性放在 ViewModel 中。

    【讨论】:

    • 嗨,金,谢谢。由于 IdeaBlade DRC 中的以下文本,我认为我误导了自己“一种更清洁、更简单的方法是在 .NET 项目或客户端项目中创建额外的部分类文件,并且故意不链接它们。”这让我觉得有一些“秘方”可以做到这一点。这段代码用于一些导航结构,我希望不必为了保存结构和实体而编写整个 VM,看起来我可能不得不重新考虑我的猜测。感谢您的快速回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 2019-10-06
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多