CompositeId() .KeyProperty(x => x.title) .KeyProperty(x => x.label);The following exception is raised when trying to create a composite key
CreateSessionFactory() - Inner exception: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. .. CreateSessionFactory() - Inner exception: Could not compile the mapping document: (XmlDocument) CreateSessionFactory() - Inner exception: composite-id class must override Equals(): CSharpTechies.Data.Entities.postThis means "post" entity definition should override at least 2 members GetHashCode() and Equals(object obj) Now here is how code snippet looks
public override int GetHashCode() { int hashCode = 0; hashCode = hashCode ^ title.GetHashCode() ^ label.GetHashCode(); return hashCode; } public override bool Equals(object obj) { var toCompare = obj as post; if (toCompare == null) { return false; } return (this.GetHashCode() != toCompare.GetHashCode()); }Remember if the entity "post" is referenced elsewhere (ie.. foreign key) then you might get some more exceptions
CreateSessionFactory() - caught EXCEPTION: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. .. CreateSessionFactory() - Inner exception: Foreign key (FK36342426872A80CB:AuthorPosts [Post_id])) must have same number of columns as the referenced primary key (Post[title, label])So update reference mapping as
References(x => x.Post) .Columns(new string[] { "title", "label" }) .Not.Update() .Not.Insert();or one-to-many mapping as
HasMany(x => x.Posts) .KeyColumns.Add("title") .KeyColumns.Add("label") .Not.LazyLoad() .Inverse();
“We have to stop optimizing for programmers and start optimizing for users.” – Jeff Atwood
Great Article
ReplyDeleteASP.NET MVC Training
Online MVC Training
Online MVC Training India
Dot Net Training in Chennai
.Net Online Training
.net training online
Dot Net Online Training
C# Training