RIA Services + Entity Framework 4 + POCO: Timestamp Field Error?

I have the following table definition in 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
)
;

The EDMX property for Timestamp is as follows: (Note that only the red property has changed by me manually)

alt text http://i35.tinypic.com/2ez7g9k.png

I used the t4 template to automatically create POCO objects. The custom object is as follows:

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;
    }

    ...
}

When I perform the SaveChanges operation in the ObjectContext, I get a validation error for the User object that is being called: Timestamp field

+3
source share
2 answers

Decision:

, 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; }
}

.

+2

- Nullable true EDMX, NOT NULL .

Timestamp (RowVersion) (byte[]) null, .

0

Source: https://habr.com/ru/post/1759738/


All Articles