Solved

Model mapping?

Posted on 2014-02-26
2
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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