I've been learning how to use nHibernate with Vb.net using all the examples online(which are in C#) to learn. Which has been fine for the basics, but now I'm trying to learn how to use QueryOver's JoinAlias, and going from C# to VB.net is difficult. I've been using this page's answer as a reference, but I'm still having trouble converting an example like that to Vb.net. Could someone help me?
Asked
Active
Viewed 1,792 times
1
-
Which version of VB.NET are you using? Before .NET 4, VB didn't have the same lambda support as C#. If you're using an older version, that might explain some of your problems. – John M Gant Feb 07 '12 at 16:12
1 Answers
0
Updated:
the easy way would be to introduce a collection of TableResultDetailsClass in TableResultClass and use that.
results = session.QueryOver(Of TableResultClass)() _
.Where(Function(tr) tr.Id = wantedId) _
.Select(Function(tr) New With { tr.Id, tr.Details.Sum(Function(trd) trd.Property) }) _
.List()
otherwise you get object[] back
results = session.QueryOver(Of TableResultDetailsClass)() _
.Where(Function(td) tD.Parent.Id = wantedId) _
.Select(Projections.Property(Function(td) tD.Parent.Id), Projections.Sum(Function(td) tD.Prpoerty)) _
.List()
Original:
all you need is generics and lambdas in vb.net
Dim child as Child
results = session.QueryOver(Of User)()
.Where(Function(u) u.Name = "blub")
.JoinAlias(Function(u) u.Childs, Function child)
.List()
Update: it seems you are looking for mappings. With FluentNHibernate it would look like
Public Class TableEntityMap Inherits ClassMap(Of TableEntity)
Sub New()
Id(Function(x) x.Id, "DID")
HasMany(Of TableEntity)(Function(x) x.Details).Inverse()
End Sub
End Class
Public Class TableEntityMap Inherits ClassMap(Of TableEntity)
Sub New()
Id(Function(x) x.Id)
References(Of DetailsTableEntity)(Function(x) x.Parent, "Parent")
End Sub
End Class
Dim entity as TableEntity = sess.Get(Of TableEntity)(someid)
'' get all details of this entity
Dim details = entity.Details

Firo
- 30,626
- 4
- 55
- 94
-
That's a pretty general, vague answer you have there... maybe I didn't specify enough? I'm trying to aggregate 2 different tables.. – Michael Fender Feb 07 '12 at 16:10
-
sorry was a fast shot. Maybe it is best to show a queryover you want to convert or describe what you want back from a defined schema – Firo Feb 07 '12 at 16:13
-
Okay. In this case, I have Table, and DetailsTable classes. The table has a DID, but the DetailsTable has a column that's Parent, so Table. So I'm trying to join on when DetailsTable = Table. How would I do that? And I hope that helps clarify my question. – Michael Fender Feb 07 '12 at 16:20
-
I don't think I'm looking for mappings. I'm looking for an aggregation. Err. Maybe I'll explain in more detail what I have. – Michael Fender Feb 08 '12 at 13:34
-
I have 2 tables, TableResults and TableResultsDetails. Both of them have DIDs as correlation to the correct TableResults with TableResults details. Now, looking in the project, I found out that we have two classes that are used to represent the tables. TableResultClass and TableResultDetailsClass. TableResultClass has a DID property, but TableResultDetailsClass doesn't have a DID property, but instead it has a Parent property, which has a reference to it's respective TableResultClass. – Michael Fender Feb 08 '12 at 13:46
-
Now, using nHibernate, which would be the best way to do a join QueryOver based on their DIDs, or, in this case, the Parent property? – Michael Fender Feb 08 '12 at 13:48