2012-05-09 3 views
3

저는 n 계층 응용 프로그램에서 자체 추적 엔터티를 사용하고 있습니다. 그래서 나는 데이터 레이어에 대한 클라이언트 액세스를 제공하는 WCF 서비스를 가지고 있으며, ""과 같은 내 모델에서 일부 엔티티를 가져 오는 것과 동일한 "동일한"기능을 많이 구현한다는 것을 알게되고, 클라이언트에서이를 변경 한 후에 Save(Order order) 또는 Save(TrackableCollection<Orders> orders) 작업을 변경 내용을 유지합니다.WCF 서비스 생성을위한 T4 템플릿이 존재하여 자체 추적 엔티티에 대해 가져 오기 및 저장을 제공합니까?

기본 인터페이스를 구축 할 수있는 T4 템플릿이 있는지, 내 모델의 각 개체 및 해당 서비스 구현의 단일 및 모음에 대해 가져 오기/저장이 있는지 궁금합니다.

나는이 서비스를 생성하기 위해 내 자신의 T4 템플릿을 작성할 수 있다는 것을 알고 있으며,해야만한다면 그렇게 할 것입니다.하지만 먼저이 노력이 이미 어딘가에 존재하는지 커뮤니티에 물어볼 것이라고 생각했습니다. 인터넷이 계획되어 있고, 다른 사람들이 원하는 바입니다. 그리고/또는 완전히 어리석은 생각입니다.

나는 이걸 찾았습니까? WCF Data Services Generator 예를 들어, 올바른 경로에 있습니다.

아마도 n 계층 솔루션에서 WCF를 사용하는 STE에 더 적합한 것이있을 것입니다.

답변

2

out there (more)이 있지만 맞춤 설정해야합니다. 나는 온라인에서 발견 된 간단한 템플릿을 사용자 정의했으며, 기본적으로 win32 클라이언트에 대한 가시성을위한 운영 계약 및 웹 메소드를 작성합니다. 아래는 발췌 부분입니다 :

// I obtain anykeys by iterating through the entity keys: 
_anyKeys = string.Format("{0}{1} item.{2} == {3}_dto.{2}", _anyKeys, _and, key.ToString(), _double); 
    // loop through all the entities: 
    foreach (EntityType entity in Item1Collection.GetItems<EntityType>().OrderBy(e => e.Name)) 
    { 

    /// <summary> 
    /// <#=code.Escape(entity)#> Operation contracts - <#=code.Escape(entityName)#> 
    /// </summary> 
    [WebMethod] 
    public bool Save<#=code.Escape(entity)#>(Dto<#=code.Escape(entity)#> _dto, int racID, string profile) 
    { 
     try 
     { 
      // Load the db 
      using (<#=ContextName#> db = new <#=ContextName#>(EFUtils.GetEFConnectionString(profile, modelName))) 
      { 
       // Check if item exists   
       var exists = db.<#=code.Escape(entityName)#>.Any(item=> <#=code.Escape(_anyKeys)#>); 
       // convert to entity 
       var _entity = _dto.ToEntity(); 
       if(exists) 
       { 
        // Attach the entity to the db 
        db.<#=code.Escape(entityName)#>.Attach(_entity); 
        // Change tracking 
        ChangeTracking<<#=code.Escape(entity)#>>(_dto.ModifiedProperties, db, _entity); 
       } 
       else 
       { 
        // New entity 
        db.<#=code.Escape(entityName)#>.Add(_entity); 
       } 
       // Save changes 
       return db.SaveChanges() > 0; 
      } 
     } 
     catch(Exception ex) 
     {    
      Global.LogMessageToFile(ex, string.Format("{0} - profile {1}, Save<#=code.Escape(entity)#>", racID, profile)); 
     } 
     finally 
     {  
     } 
     return false; 
    } 


// Then the interfaces 
#> 
#region <#=code.Escape(entity)#> 
    /// <summary> 
    /// <#=code.Escape(entity)#> Operation contracts - <#=code.Escape(entity.Name)#> 
    /// </summary> 
    [OperationContract] 
    bool Save<#=code.Escape(entity)#>(Dto<#=code.Escape(entity)#> _dto, int racID, string profile); 
    [OperationContract] 
    bool Delete<#=code.Escape(entity)#>(<#=code.Escape(_keys)#>, int racID, string profile); 
    [OperationContract] 
    Dto<#=code.Escape(entity)#> Get<#=code.Escape(entity)#>(<#=code.Escape(_keys)#>, string filterXml, int racID, string profile); 
    [OperationContract] 
    List<Dto<#=code.Escape(entity)#>> List<#=code.Escape(entityName)#>(string filterXml, int racID, string profile); 
#endregion 
<#+ 
+0

감사합니다! 내 솔루션에서 각 레이어에 대한 기본 구성 요소를 생성하는 것을 처리하기 위해 처음부터 직접 작성했지만 결국 다른 사람들을위한 훌륭한 시작점처럼 보입니다. – Erikest