2016-11-18 1 views
3

episerver의 동적 데이터 저장소를 사용하여 유지하기 전에 주어진 ID를 엔티티에 지정할 때 엔티티가 지속되지 않습니다. 자습서에 따르면 나는 이것이 잘되어 있어야한다는 것을 보았습니다. 모든 단서? 예외는 발생하지 않으며 Save 호출은 id를 지정한 엔터티의 Id를 반환합니다.ID를 지정할 때 DDS가 엔티티를 저장하지 않습니다.

var winnerEntity = new DailyXMasLotteryWinner 
{ 
    Id = Identity.NewIdentity(guid), 
    FullName = fullName, 
    Email = email, 
    Phone = phone, 
    WinnerTime = DateTime.Now 
} 

winnerStore.Save(winnerEntity); // does not persist to database! 
winnerStore.Items().Count() == 0; 
winnerEntity.Id = null; 
winnerStore.Save(winnerEntity); // persists to database just fine! 
winnerStore.Items().Count() == 1; 
+1

"Id"속성 이름이 보호되어있어 기존 개체를 덮어 쓰는 경우에만 해당 값을 설정해야합니까? 다시 말해서, 귀하의 부동산이 "WinnerId"라고 불리는 경우, 그 부동산은 효과가 있습니까? –

+0

'guid' 매개 변수에는 무엇이 포함되어 있습니까? 어떻게 구성합니까? –

+0

안내입니다. Guid.NewGuid() – oligofren

답변

0

나는 당신의 패턴을 잘 모르는 것 같아요 그러나 이것은 내가 일반적으로 DDS

using System; 
using System.Linq; 
using EPiServer.Data; 
using EPiServer.Data.Dynamic; 
using EPiServer.ServiceLocation; 

namespace Herlitz.EPiBlog.Models.DDS 
{ 

    public interface IDailyXMasLotteryWinner 
    { 
     DailyXMasLotteryWinner Create(string fullName); 

     DailyXMasLotteryWinner Get(string fullName); 

     bool Exist(string property, string value); 
    } 

    [ServiceConfiguration(typeof(IDailyXMasLotteryWinner))] 
    public class DailyXMasLotteryWinner : IDailyXMasLotteryWinner //,IDynamicData 
    { 
     private readonly DynamicDataStore _store = DynamicDataStoreFactory.Instance.CreateStore(typeof(DailyXMasLotteryWinner)); 

     public Identity Id { get; set; } 

     public string FullName { get; set; } 

     public DailyXMasLotteryWinner Create(string fullName) 
     { 
      if (Exist(property: "FullName", value: fullName)) 
      { 
       return Get(fullName: fullName); 
      } 

      Id = Identity.NewIdentity(Guid.NewGuid()); 
      FullName = fullName; 

      _store.Save(this); 
      return this; 
     } 

     public DailyXMasLotteryWinner Get(string fullName) 
     { 
      return _store.Find<DailyXMasLotteryWinner>(propertyName: "FullName", value: fullName).FirstOrDefault(); 
     } 

     public bool Exist(string property, string value) 
     { 
      return _store.Find<DailyXMasLotteryWinner>(propertyName: property, value: value).Any(); 
     } 
    } 
} 

@{ 

    var xmasLocator = ServiceLocator.Current.GetInstance<IDailyXMasLotteryWinner>(); 
    var winner = xmasLocator.Create(fullName: "Ned Flanders"); 

    <div>@winner.Id @winner.FullName</div> 
} 

과 테스트 구현 방법이며

enter image description here

를 작동

이 패턴을 패턴에 맞게 조정해야합니다. 제대로 작동하지 않으면 권한이 충분하지 않은 데이터베이스 사용자 일 가능성이 큽니다.

관련 문제