c# - Multiplicity constraint violated. The role "....' of the relationship '...' has multiplicity 1 or 0..1 -


again stucked un-clrear error raised ef. have following model class:-

public partial class tmsserver     {         public tmsserver()         {             this.tmsservers1 = new hashset<tmsserver>();             this.tmsvirtualmachines = new hashset<tmsvirtualmachine>();         }          public int tmsserverid { get; set; }         public nullable<int> servermodelid { get; set; }         public int datacenterid { get; set; }         public string iloip { get; set; }         public int rackid { get; set; }         public nullable<int> statusid { get; set; }         public nullable<int> backupstatusid { get; set; }         public int roleid { get; set; }         public nullable<int> operatingsystemid { get; set; }         public nullable<int> virtualcenterid { get; set; }         public string comment { get; set; }         public byte[] timestamp { get; set; }         public long it360siteid { get; set; }          public virtual datacenter datacenter { get; set; }         public virtual operatingsystem operatingsystem { get; set; }         public virtual servermodel servermodel { get; set; }         public virtual technology technology { get; set; }         public virtual technologybackupstatu technologybackupstatu { get; set; }         public virtual technologyrole technologyrole { get; set; }         public virtual technologystatu technologystatu { get; set; }         public virtual tmsrack tmsrack { get; set; }         public virtual icollection<tmsserver> tmsservers1 { get; set; }         public virtual tmsserver tmsserver1 { get; set; }         public virtual icollection<tmsvirtualmachine> tmsvirtualmachines { get; set; }     } } 

and following post create action method:-

 [httppost]         [validateantiforgerytoken]         public actionresult create(serverjoin sj, formcollection formvalues)         {             string controllername = routedata.values["controller"].tostring();             if (modelstate.isvalid)             { //code goes here                          repository.insertorupdateserver(sj.server, user.identity.name, assetid);                         repository.save() 

and following repository method:-

public void insertorupdateserver(tmsserver server, string username,long assetid)         {             var resource = getresourcedetials(assetid);             if (server.tmsserverid == default(int))             {                 // new entity                int technologyypeid = gettechnologytypeid("server");                 technology technology = new technology                 {                     isdeleted = true,                     typeid = technologyypeid,                     tag = "s" + gettagmaximumenumber(technologyypeid).tostring(),                     startdate = datetime.now,                     it360id = assetid                  };                  insertorupdatetechnology(technology);                 save();                    var auditinfo = intiatetechnologyaudit(tms.auditactions.singleordefault(a => a.name.toupper() == "add").id,                 tms.technologytypes.singleordefault(a => a.name.toupper() == "server").assettypeid,                 username, technology.technologyid);                  server.tmsserverid= technology.technologyid;                 server.it360siteid = resource.siteid.value;                               tms.tmsservers.add(server);                                technology.isdeleted = false;                 insertorupdatetechnology(technology);                 insertorupdatetechnologyaudit(auditinfo);             }          } 

;

but when try call post create action method following exception:-

system.invalidoperationexception unhandled user code
hresult=-2146233079 message=multiplicity constraint violated. role 'tmsservers' of relationship 'tmsmodel.fk_servers_technology' has multiplicity 1 or 0..1. source=system.data.entity stacktrace:

the technology model class envlved in exception looks follow:-

public partial class technology     {         public technology()         {             this.tmsswitchports = new hashset<tmsswitchport>();             this.technologyaudits = new hashset<technologyaudit>();             this.technologyips = new hashset<technologyip>();         }          public int technologyid { get; set; }         public string tag { get; set; }         public bool isdeleted { get; set; }         public byte[] timestamp { get; set; }         public nullable<int> typeid { get; set; }         public nullable<system.datetime> startdate { get; set; }         public nullable<long> it360id { get; set; }          public virtual tmsfirewall tmsfirewall { get; set; }         public virtual tmsrack tmsrack { get; set; }         public virtual tmsrouter tmsrouter { get; set; }         public virtual tmsserver tmsserver { get; set; }         public virtual tmsstoragedevice tmsstoragedevice { get; set; }         public virtual tmsswitch tmsswitch { get; set; }         public virtual icollection<tmsswitchport> tmsswitchports { get; set; }         public virtual technologytype technologytype { get; set; }         public virtual icollection<technologyaudit> technologyaudits { get; set; }         public virtual icollection<technologyip> technologyips { get; set; }         public virtual tmsvirtualmachine tmsvirtualmachine { get; set; }     } 


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -