Solved

Model mapping?

Posted on 2014-02-26
2
151 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

22 Experts available now in Live!

Get 1:1 Help Now