Add a new part to (Content Type: Blog) and error when get it

Topics: Administration, Core, Customizing Orchard, Writing modules
Mar 28, 2012 at 10:01 AM
Edited Mar 28, 2012 at 10:34 AM

Hi Everyone,

I have write a new part: MediaListPart

            SchemaBuilder.CreateTable("MediaListPartRecord", table => table
                .ContentPartRecord()
                .Column("MediaListName", DbType.String)
                .Column("MediaFileType", DbType.String)
                .Column("DisplayMediaList", DbType.Boolean)
                .Column("SelectMediaListPlugin", DbType.Byte)
            );

Define a part:

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

This part is build success, and i add  it into a ContentType and run OK. When i add it into Blog's ContentType in module Orchard.Blog everything is right but when i get MediaListPart from Blog's ContentType then have an error

var mediaListPart = _contentManager.Get<MediaListPart>(id); //id = MediaListPart's Id

Don't get MediaListPart from Blog's ContentType, Why??

Please help me!

Coordinator
Mar 28, 2012 at 6:27 PM

You'll have to give a lot more details about what you're expecting, how it doesn't work, etc. if you want answers. As it is, it would be an exercise in divination ;)

Developer
Mar 28, 2012 at 7:11 PM

What is the problem? But I guess you don't have a Driver for your part, right? If you don't have a driver, you can't "cast" content items to a part either.

Mar 29, 2012 at 3:25 AM
Piedone wrote:

What is the problem? But I guess you don't have a Driver for your part, right? If you don't have a driver, you can't "cast" content items to a part either.

My part have a Driver and have anything for a base part, the Driver is many code so i don't post in here. When i add it into Page ContentType or any ContentType i have get Part form it's Id, but when i add into BlogPost ContentType then i don't get Part, although it have create a new record in database.

Developer
Mar 29, 2012 at 7:52 PM

So you're querying the content items with a valid id, but it still doesn't return the part. What is the result? Null?

Mar 30, 2012 at 5:29 AM
Edited Mar 30, 2012 at 5:29 AM
Piedone wrote:

So you're querying the content items with a valid id, but it still doesn't return the part. What is the result? Null?

Exactly, the result is Null. when i'm querying by IRepository it Ok, but when i querying by Contentmanager it fail. Yesterday i showed BlogPostPart's code and realize it don't have a driver and don't have a BlogPostPartRecord table in database. So, what should I do?

Developer
Mar 30, 2012 at 8:21 AM

How exactly are you attaching your MediaListPart? From the admin UI?

What happens if you make a query for that content item, without adding the part as a type parameter?

How BlogPostPart is implemented should not affect what you're wanting to do.