0

I'm new to ASP.Net and I'm trying to develop a model that represents Logs from a system, but the controller wizard (that creates the scaffolding views), and the code first approach are not creating all the columns.

This is my model's definition:

namespace Project.Models
{
    public enum SystemComponents : byte
    {
        Component1, Component2, Component3
    }

    public enum LogMessageCategory : byte
    {
        Warning, Error, Debug, Log
    }

    public class LogDbContext : DbContext
    {
        public DbSet<Log> Logs { get; set; }
    }

    public class Log
    {
        public int ID { get; set; }

        [Required]
        public SystemComponents AffectedComponent;

        [Required]
        public LogMessageCategory MessageCategory;

        [Display(ResourceType = typeof(Resources.Resources), Name = "EventDate")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Required]
        public DateTime EventDate { get; set; }

        /// <summary>
        /// Foreign Key that represents the event's emisor.
        /// This can be both a User, or a System component
        /// </summary>
        public int ActorID { get; set; }

        /// <summary>
        /// Foreign Key that represents the event's emisor.
        /// This can be both a User, or a System component
        /// </summary>
        public int ComponentID { get; set; }
}

What am I doing wrong? Also, what's the correct way to display this property in Views that use Resources (for internationalization)? (as this model's instances are going to be created by the system, I don't care abut how to display a field in a Create view)

Also, additional question, do I have to declare public all my properties in order to use them? Online tutorials do not explain this, but fields are not created in databases if not.

P.D. I think I'm using EF 6.0 (VS 2013 Premium)

1 Answer 1

1

You probably just need to expose them as properties, instead of public fields.

[Required]
public SystemComponents AffectedComponent{ get; set; }

[Required]
public LogMessageCategory MessageCategory{ 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.