2012-04-21 4 views
4

맞춤 모듈이 있습니다. Migrations.cs는 다음과 같습니다.콘텐츠 오류 만들기 - 지정된 캐스트가 유효하지 않습니다.

public int Create() 
    { 
     SchemaBuilder.CreateTable("MyModuleRecord", table => table 
      .ContentPartRecord() 
      ... 
     ); 

     ContentDefinitionManager.AlterPartDefinition(
      typeof(MyModulePart).Name, cfg => cfg.Attachable()); 

     ContentDefinitionManager.AlterTypeDefinition("MyModule", 
      cfg => cfg 
       .WithPart("MyModulePart") 
       .WithPart("CommonPart") 
       .Creatable() 
      ); 

     return 1; 
    } 

이것은 컨트롤러에있는 코드입니다.

var newcontent = _orchardServices.ContentManager.New<MyModulePart>("MyModule"); 
    ... 
    _orchardServices.ContentManager.Create(newcontent); 

나는 Orchard.ContentManagement ContentCreateExtensions에서이 새로운 방법에서 잘못된 캐스트 오류가 발생합니다.

public static T New<T>(this IContentManager manager, string contentType) where T : class, IContent { 
     var contentItem = manager.New(contentType); 
     if (contentItem == null) 
      return null; 

     var part = contentItem.Get<T>(); 
     if (part == null) 
      throw new InvalidCastException(); 

     return part; 
    } 

내가 뭘 잘못하고 있다고 생각 하나?

감사합니다.

이것은 처리기입니다.

public class MyModuleHandler : ContentHandler 
{ 
    public MyModuleHandler(IRepository<MyModuleRecord> repository) 
    { 
     Filters.Add(StorageFilter.For(repository)); 
    } 
} 
+0

당신이 당신의 드라이버/핸들러 코드를 게시 할 수 : 당신이 ActivatingFilter에 당신의 부분의 핸들러 클래스가 명시 적으로 링크를 만들 것입니다 추가 드라이버가없는 그러나 이후

? – mdm

+0

드라이버가 없습니다. 게시물을 처리기 코드로 업데이트했습니다. – user471317

답변

7

을 당신이 얻고있는 InvalidCastException 컨텐트 항목이 MyModulePart 부착이 표시되지 않습니다 때문이다.

사용자가 사용할 드라이버가있는 경우 콘텐츠 항목에 사용자의 파트를 표시 할 수있는 어딘가에 암시 적 링크가 있습니다 (이 작업이 어떻게 수행되는지는 잘 모르겠지만 누군가 다른 사람이 정교하게 작업 할 수도 있음). 과수원의 핵심 깊은 모양 테이블에 의해 형상이 수확되고 픽업되는 방식과 관련이 있습니다.

public MyModulePartHandler : ContentHandler { 
    public MyModulePartHandler() { 
     Filters.Add(StorageFilter.For(repository)); 
     Filters.Add(new ActivatingFilter<MyModulePart>("MyModule"); 
    } 
} 
+0

고맙습니다. 그게 다야, 지금은 효과가있다. – user471317

0

부품 표 이름이 잘못되었습니다. (그래서 "기록"전에 부품이 정확하게 당신의 부분 모델 이름과 일치)이로 이름을 변경 시도 :

SchemaBuilder.CreateTable("MyModulePartRecord", table => table 
     .ContentPartRecord() 
     ... 
    ); 
+0

그게 문제인지 확실하지 않습니다. 위와 같은 형식으로 테이블 이름을 가진 다른 모듈이 있는데, 레코드입니다. 그 모듈은 잘 작동합니다. – user471317

관련 문제