【问题标题】:RIA DomainService + ActiveRecordRIA DomainService + ActiveRecord
【发布时间】:2013-01-04 07:30:26
【问题描述】:

我尝试在使用 .NET RIA 服务的 SL3 项目中使用 SubSunsonic.ActiveRecord。 但是,当我尝试在 DomainService 类中返回一些 IQuerable 时,我收到一个错误,即 Subsonic 生成的类具有不支持类型的属性“列”。 这就是我所拥有的

public IEnumerable<SE_NorthWind.SuperEmployee> GetIntegers()
{
  return SE_NorthWind.SuperEmployee.All()
    .Where(emp => emp.Issues > 100)
    .OrderBy(emp => emp.EmployeeID);
}

这是我得到的错误

Error   7   Entity 'SE_NorthWind.SuperEmployee' has a property 'Columns' with an unsupported type.  SuperEmployee

知道该怎么做吗?真的不想使用 Linq to SQL :)

谢谢

附:刚刚尝试从 SubSonic 使用 LinqTemplates,但是这个解决方案我得到了错误

Error   4   The entity 'SE_NorthWind.SuperEmployee' does not have a key defined. Entities exposed by DomainService operations must have must have at least one property marked with the KeyAttribute.   SuperEmployee

当然 SuperEmployee 表有一个主键,因为 SubSonic 生成的类可以看到它

...
Columns.Add(new DatabaseColumn("EmployeeID", this)
            {
                IsPrimaryKey = true,
                DataType = DbType.Int32,
                IsNullable = false,
                AutoIncrement = true,
                IsForeignKey = false,
                MaxLength = 0
            });
...

但是 RIA 对象,它们需要一些属性。我想我将不得不使用本机 Linq To SQL,直到 SubSonic 适应所有这些:(

【问题讨论】:

    标签: activerecord subsonic3


    【解决方案1】:

    回答你问题的第二部分。

    您需要将“KeyAttribute”添加到“EmployeeId”属性的 PrimaryKey 属性中。 该属性位于“System.ComponentModel.DataAnnotations”命名空间中。

    在 Sub Sonic 3 上没有,但您可以更改底层模板来生成它,或者更改 sub sonic 引擎并将其作为补丁提交。

    我正在使用带有 RaiServices 的 SilverLight 3。

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      您能否尝试删除 [EnableClientAccess()] 属性以查看您的项目是否会构建?

      【讨论】: