Invalid Association when domain service indirectly derived from DbDomainService<TContext>

Jul 12, 2012 at 1:52 PM

Thank you for this package, which is going to be very useful. I have a question about the domain service.

M2M4RiaDemoService in the sample project is derived from DbDomainService<DogTrainerModel>.  If, however, it derives from an intermediate class e.g. EmptyDbDomainService<DogTrainerModel>, where EmptyDbDomainService is

    public class EmptyDbDomainService<TContext> : DbDomainService<TContext>

        where TContext : DbContext, new()

    {

    }

 

the following compilation error occurs:

Association named 'Dog_DogTrainers' defined on entity type 'RIAServices.M2M.Demo.Web.Model.Dog' is invalid: ThisKey cannot be null or empty.

Is this a known restriction? We have an intermediate class that overrides DomainService.Query. The work-around is, of course, to collapse the inheritance, so it’s no big deal.

Regards,

Richard Hill.

Coordinator
Jul 12, 2012 at 8:09 PM

Hi Richard,

Thanks for using m2m4ria.

This is certainly not an intend restriction. It turned out to be a subtle bug in the FluentMetadata package. I've fixed this bug and published a new version of FluentMetadata to Nuget.org. You can now use the update mechanism of Nuget to get this latest version of the FluentMetadata package which should solve your problem. If not, please le tme know.

Kind regards,

Merijn

Jul 16, 2012 at 8:48 PM

Thank you Merijn, that got my code compiling. :-)


I have another question about the demo project. If I comment out


_c.Load(c.GetTrainersQuery());


from MainPageModel.M2M4RiaDemoContext, it still loads trainers that have dogs, but if I instead comment out


_c.Load(c.GetDogsQuery());


it doesn’t load any of the dogs (or DogTrainers), and Trainer.Dogs is empty for each trainer. Does this mean that the direction of the projection in MetadataConfiguration is significant? I can’t repeat the projection in reverse, because that leads to duplicated code in the context. Should I always load the dogs explicitly when I want to navigate from trainers to dogs?


Regards,

Richard.

Coordinator
Jul 30, 2012 at 9:02 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.