Hi, I'm using ASP.NET MVC, C#, NHibernate v2.0.50727 and FluentNHibernate. I have 2 tables that has one to many relationship. I want to do a select query by joining them but I am getting the following error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, jcs-cache, cache, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'.
After searching the internet, it seems one of the posting says that I need to declare an ID in table mapping. The problem is that one of the table doesn't have a primary key as id field. The Application Field has a primary key and the ApplicationResearchInterests table servers as a middle table for manyToMany relationship between Application table and the ReserachInterests table so it only contains 2 foreign keys for mapping these 2 tables. Below is my class map and the query that's giving me the error message. I appreciate any help here.
public IList<Application> FindMembersByInterestIds(string ids) { var query = "select distinct a from Applications a" + " join ApplicationResearchInterests ar on a.Id = ar.ApplicationId" + //" where ar.ResearchInterestId in('2', '574', '110', '1111', '1123')"; " where ar.ResearchInterestId in( " + ids + ")"; IList<Application> applications = Database.Session.CreateQuery(query).List<Application>();
return applications; }
using CtsiSearchMembership.Models; using FluentNHibernate.Mapping;
namespace CtsiSearchMembership.ModelMapping { public class ApplicationResearchInterestsMap : ClassMap<ApplicationResearchInterests> { public ApplicationResearchInterestsMap() { WithTable("ApplicationResearchInterests"); Map(x => x.ApplicationId); Map(x => x.ResearchInterestId); } } }
using CtsiSearchMembership.Models; using FluentNHibernate.Mapping;
namespace CtsiSearchMembership.ModelMapping { public class ApplicationMap: ClassMap<Application> { public ApplicationMap() { WithTable("Applications"); Id(x => x.Id); Map(x => x.FirstName); Map(x => x.LastName); Map(x => x.EmailAddress); Map(x => x.PhoneNumber); Map(x => x.MailingAddressLine1); Map(x => x.MailingAddressLine2); Map(x => x.MailingAddressCity); Map(x => x.MailingAddressState); Map(x => x.MailingAddressZip); Map(x => x.Institution); Map(x => x.InstitutionOther); Map(x => x.CommunityOrganization); References(x => x.Title); Map(x => x.TitleOther); Map(x => x.Department); Map(x => x.ProfessionalOrganizations); Map(x => x.MembershipLevel); Map(x => x.MembershipReasonOther); Map(x => x.PhdTraineeCount); Map(x => x.MscTraineeCount); Map(x => x.Gender); Map(x => x.YearOfBirth); Map(x => x.Race); Map(x => x.RaceOther); Map(x => x.Ethnicity);
//Many to Many mappings HasManyToMany<ResearchInterest>(x => x.ResearchInterests).AsBag().WithTableName( "ApplicationResearchInterests").WithParentKeyColumn("ApplicationId").WithChildKeyColumn( "ResearchInterestId"); HasManyToMany<Degree>(x => x.Degrees).AsBag().WithTableName("ApplicationDegrees").WithParentKeyColumn( "ApplicationId").WithChildKeyColumn("DegreeId"); HasManyToMany<MembershipReason>(x => x.MembershipReasons).AsBag().WithTableName( "ApplicationMembershipReasons").WithParentKeyColumn("ApplicationId").WithChildKeyColumn( "MembershipReasonId"); HasManyToMany<MembershipServiceRequirement>(x => x.MembershipServiceRequirements).AsBag().WithTableName( "ApplicationMembershipServiceRequirements").WithParentKeyColumn("ApplicationId").WithChildKeyColumn( "MembershipServiceRequirementId"); } } }
|