コードを実行すると、挿入時に次のエラーが発生します
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();
}