1

I have the following model:

public class Movie
{
    public int Id { get; set; }

    [Required]
    public string Title { get; set; }

    [DataType(DataType.DateTime)]
    [Display(Name = "Release date")]
    [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}")]
    public DateTime ReleaseDate { get; set; }

    [Required]
    public string Genre { get; set; }

    [Required]
    [Range(1, 20)]
    public decimal Price { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    public string Email
    {
        get;
        set;
    }

    [Compare("Email")]
    public string ConfirmEmail
    {
        get;
        set;
    }
}

and Db context:

public class MovieDbContext : DbContext
{
    public DbSet<Movie> Movies { get; set; }
}

and my table looks like:

CREATE TABLE [dbo].[Movies] (
    [Id]          INT            IDENTITY (1, 1) NOT NULL,
    [Title]       NVARCHAR (50)  NOT NULL,
    [ReleaseDate] DATETIME       NOT NULL,
    [Genre]       NVARCHAR (50)  NOT NULL,
    [Price]       DECIMAL (6, 2) NOT NULL,
    [Email]       NVARCHAR (100) DEFAULT ('') NOT NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);

As you see, I added a new property called ConfirmEmail attached to Movie model. But I didn't add to table and I don't want to.

When run application, an error is occured:

Unknown column name ConfirmEmail.

Does it is possible to exclude that ConfirmEmail from context ?

It is just used as parameter to be compared to Email property.

Thanks

1 Answer 1

4

Use the NotMappedAttribute

[NotMapped]
public string ConfirmEmail {get;set;}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.