Solved

Model mapping?

Posted on 2014-02-26
2
152 Views
Last Modified: 2014-03-19
When I run a page, I got object NULL value error. It seems like something may be wrong with the mapping to a field (statuscodes) in the edmx from the an entity as I passed a valid status for insert. I'm a newer. I need help on analysis and resolving.

Here's class definition -
public partial class cWorkflow
    {
        public cWorkflow()
        {
            this.Orders = new HashSet<Orders>();
            ... ...            
        }
    
        public byte flowId { get; set; }
        ...    
        ...
        public virtual StatusCodes StatusCodes { get; set; }
        public virtual ICollection<WorkfIS> WorkfIS { get; set; }
     }
}

Open in new window


This is the function for inserting  -

 
public void InsertWFTable(..., Int32? StatusCodeId,...)
        {
            Workflow workflow = new cWorkflow();
            
            ...
            workflow.StatusCodeId = StatusCodeId;
             ...
            
            DataContext.Workflows.AddObject(workflow);

            DataContext.SaveChanges();
        }

Open in new window


While debugging =>

 
public void InsertWFTable(..., Int32? StatusCodeId,...)
         {
            core_Workflow workflow = new cWorkflow();
            ... ...
            workflow.StatusCodes.statusId = StatusCodeId.HasValue ? StatusCodeId.Value : 0;
            ... ...
            DataContext.Workflows.Add(workflow);
            DataContext.SaveChanges();
        }

Open in new window



At debugging at the line below, StatusCodeId has a valid value passed in, but StatusCodes is null. I need help to find where the problem might be and how to fix.

workflow.StatusCodes.statusId = StatusCodeId.HasValue ? StatusCodeId.Value : 0;

Open in new window


I appreciate.
0
Comment
Question by:minglelinch
2 Comments
 
LVL 8

Accepted Solution

by:
Andrei Fomitchev earned 500 total points
ID: 39891175
StatusCodes _StatusCodes;
        public cWorkflow()
        {
            this.Orders = new HashSet<Orders>();
             _StatusCodes = new StatusCodes();
            ... ...            
        }
        public StatusCodes StatusCodes { get {return _StatusCodes;}; set{_StatusCodes = value;}; }
0
 
LVL 1

Author Comment

by:minglelinch
ID: 39892067
Thanks a lot for the post.

In DB, table StatusCodes and table cWorkflow have 1 to many relation.  StatusCodes is on 1 side and cWorkflow is many side. The cWorkflow class definition does have code like yours but that's for opposite which means cWorkflow & otherProperty as 1 to many.

I appreciate further help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now