gpt4 book ai didi

entity-framework - RIA 服务 + Entity Framework 4 + POCO 的 : 'The Timestamp field is required' error?

转载 作者:行者123 更新时间:2023-12-02 02:31:56 25 4
gpt4 key购买 nike

我在 MSSQL 中定义了下表:

CREATE TABLE [User] ( 
[Id] bigint identity(1,1) NOT NULL,
[Email] nvarchar(256),
[PasswordHash] nvarchar(128) NOT NULL,
[PasswordFormat] int DEFAULT ((0)) NOT NULL,
[PasswordSalt] nvarchar(10) NOT NULL,
[Timestamp] timestamp
)
;

Timestamp 的 EDMX 属性如下所示:(请注意只有红色属性已被我手动更改)

alt text

我使用 t4 模板自动生成 POCO 实体。用户实体如下所示:

public partial class User : IEntity
{
public virtual long Id
{
get;
set;
}
...

[TimestampAttribute]
[ConcurrencyCheck]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Autogenerated by T4.")]
public virtual byte[] Timestamp
{
get;
set;
}

...
}

在 ObjectContext 上执行“SaveChanges”操作时,我收到名为 User 实体的验证错误:The Timestamp field is required

最佳答案

解决方法:

我已将 T4 生成的用户类更改为:(删除了“ConcurrencyCheck”属性)

public partial class User : IEntity
{
public virtual long Id
{
get;
set;
}
...

[TimestampAttribute]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Autogenerated by T4.")]
public virtual byte[] Timestamp
{
get;
set;
}

...
}

我添加了一个通用元数据类,所有实体都使用它,不包括 Timestamp 属性:

/// <summary>
/// A MetaData which defines some default metadata for an Entity
/// </summary>
public class EntityMetaData
{
/// <summary>
/// Initializes a new instance of the <see cref="EntityMetaData"/> class.
/// </summary>
protected EntityMetaData()
{
}

/// <summary>
/// Gets or sets the timestamp.
/// Note : this field is excluded on the client.
/// </summary>
/// <value>The timestamp.</value>
[Exclude]
public byte[] Timestamp { get; set; }
}

这解决了问题。

关于entity-framework - RIA 服务 + Entity Framework 4 + POCO 的 : 'The Timestamp field is required' error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3486881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com