다음 코드는 두 번째 응답에서 Breeze BeforeSaveEntityonly only allows update to Added entities입니다. 내가 이해할 수 있듯이 ModificationDate
속성은 일반 엔터티의 알려진 속성이 아니기 때문에 그대로 사용할 수 없습니다. 내가 컴파일 오류 object does not contain a definition for 'ModificationDate' and no extension method 'ModificationDate' accepting a first argument of type 'object' could be found
엔티티에서 사용자 정의 속성을 사용할 때 컴파일 오류 코드
protected override bool BeforeSaveEntity(EntityInfo entityInfo)
{
if(entityInfo.EntityState== EntityState.Modified)
{
var entity = entityInfo.Entity;
entityInfo.OriginalValuesMap.Add("ModificationDate", entity.ModificationDate);
entity.ModificationDate = DateTime.Now;
}
}
을 우리는 다음과 같이 진행해야 있어요 : 코드의 수정 된 버전에 다음
protected override bool BeforeSaveEntity(EntityInfo entityInfo)
{
if(entityInfo.EntityState== EntityState.Modified)
{
Product entity = (Product)entityInfo.Entity;
entityInfo.OriginalValuesMap.Add("ModificationDate", entity.ModificationDate);
entity.ModificationDate = DateTime.Now;
}
}
을 Product
라는 이름의 엔티티가 ModificationDate
라는 속성을 가지고 있으며, 모든 것이 잘 정리되었습니다.
내 질문 : 무엇을 우리는 여전히 우리가 다른 엔티티 (제품, 고객, ...)이 코드를 사용하고자하기 때문에합니다 (var
선언을 사용) 일반 엔티티를 사용하려는 경우. 가능한가?
희망 사항은 분명합니다.
감사합니다.
제네릭의 일로 보입니다. 내 자신의 프로젝트는 이런 일을한다. 당신의'ModificationDate' 속성과 그 밖의 공통 사항을 가진 기본 클래스를 가지고 있고'protected override bool BeforeSaveEntity (EntityInfo entityInfo) where T : MyBaseClass' 그리고'Product' 대신'T'를 사용하십시오. –
anaximander
무슨 뜻인지 알 겠어. 귀하의 의견에 감사드립니다. – Bronzato
나는 이것을 미래의 방문객을위한 완전한 답으로 살피겠다. – anaximander