运行代码时,我在插入时收到以下错误
An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.
我的代码
using (PostDBDataContext dataContext = new PostDBDataContext())
{
if (posttypeedit.posttypemeta != null)
{
foreach (var posttypemeta in posttypeedit.posttypemeta)
{
PostTypeMeta _postmeta = new PostTypeMeta();
_postmeta.vcr_MetaKey = posttypemeta.Metatexts;
_postmeta.vcr_MetaValue = posttypemeta.Datatypes;
_postmeta.int_ModifiedBy = Authorization.UserID;
_postmeta.dtm_ModifiedDate = System.DateTime.Now;
psttyp.PostTypeMetas.Add(_postmeta);
}
}
dataContext.PostTypes.InsertOnSubmit(psttyp);
dataContext.SubmitChanges();
}