0

I am currently building an MVC site using Entity Framework. I have created following class:

using System; using System.Collections.Generic;
using System.Linq; using System.Web;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace .Models {

    public class VehicleTableData
    {
        [NotMapped]
        public Dictionary<string,string> StandardVehicleData { get; set; }

        [NotMapped]
        public Dictionary<string,string> AdditionalData { get; set; }
    } }

However, I would like it to be ignored by Entity Framework as when I try to create a view with it I get the error that there is no valid key.

enter image description here

3
  • 2
    Are you defining public DbSet<VehicleTableData> VehicleTableDatas { get; set; } in your DbContext? Commented Mar 30, 2016 at 9:33
  • yes :( thank you! it was a late night! Commented Mar 30, 2016 at 17:51
  • Ha yeah we all have them. I will add as the answer :) Commented Mar 31, 2016 at 8:33

1 Answer 1

1

If you have the class defined in your DbContext with the following line of code:

public DbSet<VehicleTableData> VehicleTableDatas { get; set; }

This will cause Entity Framework to include the class. Once the above line is removed it will not be included.

You could also remove the [NotMapped] attributes as this would only apply to properties that you would not want saved to the database in a model included in your DbContext.

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.