"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
Any reason you can't modify your query to just be.
Up vote 0 down vote favorite share g+ share fb share tw.
I'm trying to figure out how to use CompositeId to map another class. Here's a test case: The tables: TestParent: TestParentId (PK) FavoriteColor TestChild: TestParentId (PK) ChildName (PK) Age The classes in C#: public class TestParent { public TestParent() { TestChildList = new List(); } public virtual int TestParentId { get; set; } public virtual string FavoriteColor { get; set; } public virtual IList TestChildList { get; set; } } public class TestChild { public virtual TestParent Parent { get; set; } public virtual string ChildName { get; set; } public virtual int Age { get; set; } public override int GetHashCode() { return Parent.GetHashCode() ^ ChildName.GetHashCode(); } public override bool Equals(object obj) { if (obj is TestChild) { var toCompare = obj as TestChild; return this.GetHashCode()! = toCompare.GetHashCode(); } return false; } } The Fluent NHibernate maps: public class TestParentMap : ClassMap { public TestParentMap() { Table("TestParent"); Id(x => x.
TestParentId). Column("TestParentId").GeneratedBy.Native(); Map(x => x. FavoriteColor); HasMany(x => x.
TestChildList). KeyColumn("TestParentId").Inverse().Cascade.None(); } } public class TestChildMap : ClassMap { public TestChildMap() { Table("TestChild"); CompositeId() . KeyProperty(x => x.
ChildName, "ChildName") . KeyReference(x => x. Parent, "TestParentId"); Map(x => x.
Age); References(x => x. Parent, "TestParentId"); /** breaks insert **/ } } When I try to add a new record, I get this error: System. ArgumentOutOfRangeException : Index was out of range.
Must be non-negative and less than the size of the collection. Parameter name: index I know this error is due to the TestParentId column being mapped in the CompositeId and References calls. However, removing the References call causes another error when querying TestChild based on the TestParentId.
Here's the code that does the queries: var session = _sessionBuilder.GetSession(); using (var tx = session. BeginTransaction()) { // create parent var p = new TestParent() { FavoriteColor = "Red" }; session. Save(p); // creat child var c = new TestChild() { ChildName = "First child", Parent = p, Age = 4 }; session.
Save(c); // breaks with References call in TestChildMap tx.Commit(); } // breaks without the References call in TestChildMap var children = _sessionBuilder.GetSession().CreateCriteria() . CreateAlias("Parent", "p") . Add(Restrictions.
Eq("p. TestParentId", 1)) .List(); Any ideas on how to create a composite key for this scenario? Nhibernate fluent-nhibernate nhibernate-mapping mapping composite-id link|improve this question asked Mar 21 '11 at 14:08david.
Mchonechase4851412 73% accept rate.
Any reason you can't modify your query to just be _sessionBuilder.GetSession().CreateCriteria() . Add(Restrictions. Eq("Parent.
TestParentId", 1)) .List() Then get rid of the reference?
Thanks - that worked. I'm not sure it will fix all occurrences (might need to join TestChild and TestParent for other queries), but I guess I'll worry about that later. – david.
Mchonechase Mar 21 '11 at 16:23.
I found a better solution that will allow querying and inserting. The key is updating the map for TestChild to not insert records. The new map is: public class TestChildMap : ClassMap { public TestChildMap() { Table("TestChild"); CompositeId() .
KeyProperty(x => x. ChildName, "ChildName") . KeyReference(x => x.
Parent, "TestParentId"); Map(x => x. Age); References(x => x. Parent, "TestParentId") .Not.Insert(); // will avoid "Index was out of range" error on insert } }.
I found a better solution that will allow querying and inserting. The key is updating the map for TestChild to not insert records. The new map is.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.