概述
我有一个问题,我无法通过寻找其他解决方案来解决它们 . 问题是我从用户那里得到了一个应用程序 . 应用程序可以处于不同的状态,我将应用程序本身保存在APPLICATION表中,并在APPLICATIONSTATE表中保存应用程序的状态 . 当用户提交应用程序时,应将默认应用程序状态值写入应用程序状态表 . 在此期间,应用程序的状态将被更改,每次更改都应写入APPLICATIONSTATE表中 .
我正在使用Entity Framework数据库第一种方法,(Oracle EF),这里是我的数据库E-R图:
以下是Entity Framework生成的部分类:
public partial class APPLICATION
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public APPLICATION()
{
this.APPLICATIONSTATE = new HashSet();
}
public int APPLICATIONID { get; set; }
public System.DateTime APPLICATIONDATE { get; set; }
public short PROVINCEID { get; set; }
public Nullable ILCEID { get; set; }
public decimal AREA { get; set; }
public bool ISBASEMENTOK { get; set; }
public string APPLICATIONEXPLAINATION { get; set; }
public virtual PERSONEL LOJ_PERSONEL { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection LOJ_APPLICATIONSTATE{ get; set; }
}
public partial class APPLICATIONSTATE
{
public long APPLICATIONSTATEID { get; set; }
public int APPLICATIONENUM { get; set; }
public System.DateTime CURRENTTIME { get; set; }
public virtual APPLICATION LOJ_APPLICATION { get; set; }
public virtual USER LOJ_USER { get; set; }
}
我正在使用Repository模式,这是我尝试添加新应用程序和应用程序状态的代码部分:
int applicationId = int.minvalue;
USER myuser = null;
APPLICATION myApplication = this.gettingFromSomewhere();
using (HousingEntities model = new HousingEntities())
{
applicantuser = model.LOJ_PERSONEL.FirstOrDefault(p => p.PERSONELID == YeniBasvuru.PersonelId);
myApplication.LOJ_USER = applicantuser;
model.APPLICATION.Add(myApplication);
//saving the application
model.SaveChanges();
//getting the primary key of newly created application object from database.
applicationId = this.getMostCurrentIdOfApplication();
myApplication.APPLICATIONID = applicationId;
//getting the user that submits application
applicant = model.USER.FirstOrDefault(p => p.LOJ_USER.USERID == myApplication.LOJ_PERSONEL.USERID);
//if clause-1
if(applicant != null)
{
//saving the state of the application.
appState = new APPLICATIONSTATE();
//3 is the default state for application. When we need to change it to 4, newly row will be added.
appState.APPLICATIONSTATEID = 3;
appState.LOJ_APPLICATION = myApplication;
appState.LOJ_USER = applicant;
//I am getting an error here.
model.APPLICATIONSTATE.Add(appState);
model.SaveChanges();
}
}
result.TransactionResult = true;
result.rowId = applicationId;
}
//other catches removed for clarity.
catch (Exception ex)
{
islemSonuc = new FunctionResult ( ex, this._olasihataciddiyeti);
this.writeError(ex);
}
我在上面指向的行中收到错误属性'APPLICATIONID'是对象的关键信息的一部分,无法修改 . 错误 . 我怎么能克服这个错误?提前致谢 .
我怎样才能克服这个错误?提前致谢 .
最后
以上就是优美蜗牛为你收集整理的java对象set时主键丢失,属性'APPLICATIONID'是对象的关键信息的一部分,无法修改...的全部内容,希望文章能够帮你解决java对象set时主键丢失,属性'APPLICATIONID'是对象的关键信息的一部分,无法修改...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复