Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - Shouldn't my nhibernate mapping take care of this? Error: not-null property reference a null or transient value -


i have database 3 tables:

  1. project
  2. sponsor
  3. projectsponsor

in domain objects, have object project has child property called sponsors list of projectsponsor objects, this:

 ilist<projectsponsor> sponsors; 

here nhibernate mapping code:

productmap:

hasmany(x => x.sponsors).asbag().inverse().cascade.alldeleteorphan(); 

productsponsormap:

references(x => x.project).not.nullable(); references(x => x.sponsor).not.nullable(); 

here my domain objects:

public class project {     public virtual ilist<projectsponsor> sponsors { get; set; } }   public class projectsponsor {     public virtual project project { get; set; }     public virtual sponsor sponsor { get; set; } } 

ok . . issue, when try add new projects (with associated projectsponsor) database.

here code:

    foreach (project project in newprojects)    {       repository.save(project);       foreach (projectsponsor projectsponsor in project.sponsors)       {            repository.save(projectsponsor);       }    } 

i getting exception on line:

     repository.save(projectsponsor); 

saying not-null property reference null or transient value trying saved:

projectsponsor.project property complaining about. have thought set default based on nhibernate mapping.

do need have explicit piece of code have code:

projectsponsor.project = project 

or there wrong mapping files ?

if haven't set projectsponsor.project property (and no code here says have) have default value of null violate mapping condition you've placed.

nhibernate going reflect state of objects , state of objects - want of better word - broken is. remove project property on projectsponsor map , you're losing functionality because directionality of relationships in oo reverse of rdbm directionality.

i expect like:

public class projectsponsor  {          // how instantiate me!     public projectsponsor(project project, sponsor sponsor)     {         this.project = project;         this.sponsor = sponsor;     }      protected projectsponsor()     {         // exist nhibernates benefit only!     }      public virtual project project { get; set; }           public virtual sponsor sponsor { get; set; }  } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -