Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Model mapping?

Posted on 2014-02-26
2
Medium Priority
?
157 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 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

715 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