Solved

Model mapping?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
Release Dynamically Allocated Memory in C# 3 38
"Emulate" TAB key when press Enter Key 3 49
JQuery Detecting page post back 6 13
itextsharp with c# 3 10
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

807 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