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 modules.Add(m);
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
{
get
{
return this._taakList;
}
set
{
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


Sign In
Create Account


Back to top









