This project is read-only.

Storing and Retrieving Custom Data from a Command

Topics: Customizing Orchard, Troubleshooting, Writing modules
Mar 9, 2012 at 12:48 AM
Edited Mar 9, 2012 at 1:02 AM


I am writing a module that has some custom commands in it. I need one of the commands to be able to retrieve some data from the CMS database.

I am trying to follow the steps in this entry - and I think I've done everything right - created the migration, the record, the the service interface, the service with the repository injected, and injecting the service into the command. Everything seems to hook up fine, but _repository.Table doesn't seem to bring anything back. It brings back an empty collection.

I pre-populate the data outside of orchard at deployment time, so there's definitely data in the database.

When I run a SQL server trace, I can't seem to pick up the query on that table being run on the database.

Any ideas on what the problem might be? Thanks in advance.

Here are relevant snippets of my code:

The migration:

            table => table
                .Column<int>("Id", column => column.PrimaryKey().Identity())
                .Column<string>("Name", c => c.WithLength(200))
                .Column<string>("Branch", c => c.WithLength(200)));

The record:

    public class EnvironmentRecord
        public virtual string Name { get; set; }

        public virtual string Branch { get; set; }

The service interface:

    public interface IExtendedCommandsService : IDependency
        EnvironmentRecord GetEnvironment();

The service:

public class ExtendedCommandsService : IExtendedCommandsService
private readonly IRepository<EnvironmentRecord> _environmentRepository;
        public ExtendedCommandsService(
            IRepository<EnvironmentRecord> environmentRepository) {
            _environmentRepository = environmentRepository;

            T = NullLocalizer.Instance;
            Logger = NullLogger.Instance;

        public EnvironmentRecord GetEnvironment()

Mar 9, 2012 at 12:58 AM

You're missing the Id on the record.

Mar 9, 2012 at 2:16 AM

Oh...of course! It would be embarrassing to admit how many hours I've spent trying to track down the problem chasing rabbits down their convoluted holes.

I am humbled. Thank you Bertrand, and especially so for the lightning fast reply.