Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -


asp.net mvc

  • Please log in to reply
No replies to this topic

#1 Shaddix


    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 102 posts

Posted 10 May 2010 - 11:54 PM

Hi, I'm using ASP.NET MVC1 and Linq to build a website

when I add objects of the partial class Module (based on the table in our DB) some things go wrong

below you find the piece of code that is probably causing this problem

List<Module> modules = new List<Module>();

SEMOI.Models.Module m = new SEMOI.Models.Module();
                    m.naam = standaardM.naam;
                    m.comiteId = _comiteId;
                    m.id = volgendeModuleId;
                    m.divisieId = standaardM.divisieId;
                    m.eventId= eventId;
                    m.frequentieMeetings = (int)SEMOI.Enumeration.Frequentie.Wekelijks;
                    m.initiatieEindDatum = DateTime.MinValue;
                    m.initiatieStartDatum = DateTime.MinValue;
                    m.planningEindDatum = DateTime.MinValue;
                    m.planningStartDatum= DateTime.MinValue;
                    m.uitvoeringEindDatum = DateTime.MinValue;
                    m.uitvoeringStartDatum = DateTime.MinValue;
                    m.Comite = new Comite();//This shouldn't be there
                    m.TaakList = new List<Taak>();//This shouldn't be there


I marked 2 lines of code that shouldn't be there

- if I don't put them there you get a Null Reference Exception
- if you put them there, all the foreign keys disapear when they are in the list (the object is fine before it is in the list)
- if you put those lines before the FK are defined you get an error that says that you want to overwrite a FK

our partial class of Module looks like this:

using System;
using System.Collections.Generic;
using SEMOI.Enumeration;
using System.Web;
using System.Web.Mvc;
using System.Linq;
using SEMOI.Models.Repository;
using System.Data.Linq;

namespace SEMOI.Models
    public partial class Module
        public Module(int eventId, int divisieId, int comiteId) 
            this.eventId = eventId;
            this.divisieId = divisieId;
            this.comiteId = comiteId;
        private IEnumerable<Taak> _taakList;
        public IEnumerable<Taak> TaakList
                return this._taakList;
                this._taakList = value;

in both the partial class and table there is no such thing as "Comite" (except for a FK called comiteId)
so there is no reason why you could do m.Comite, the fact that you have to initialize it to not have a Null Reference Exception is even more weird

if someone has some suggestions where I should look at, I would greatly appreciate it
  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download