MS Entity Framework VS NHibernate And Its Derived Contribs (FluentNHibernate, Linq For NHibernate)?
Feb 4, 2010
I just read this article about the Entity Framework 4 (actually version 2).Entity Framework seems to offer a huge improvement over its first release. Thus, I have never ever used EF in any project, since I think EF is not mature enough in comparison to NHibernate.NHibernate and its current contributions of FluentNHibernate and Linq for NHibernate by Ayende RahienMy feeling is that Microsoft is solely trying to gain terrain it has lost in favor of NHibernate when the 2nd version of NHibernate came out.Nevertheless, my concerns are the followings (not in particular order):Will EF4 tend to be less XML-verbose?Will EF4 be compatible with other underlying datastore than just SQL Server?What are the greatest benefits of going with EF4 instead of FluentNHibernate or NHibernate itself.
NHibernate is a great tool, I guess everyone agrees. Due to its predecessor Hibernate, we may easily find documentions and tutorials and sample applications to get acquainted with it. This is not the case for FluentNHibernate. Particularly as per the project I'm working on right now which demands that I investigate further about NHibernate and its options (FluentNHibernate for instance) in order to document the rules of usage and the best practices of NHibernat and FluentNHibernate technology. Thus, being handcuffed with VB.NET, being a C-Style developer, I can't find some syntax equivalencies in VB.NET for the examples provided, though I made I way so far
View 3 Replies
ADVERTISEMENT
Feb 4, 2010
I'm a C# programmer constrained to write VB.NET code.While exploring NHibernate further for my current client, I encountered FluentNHibernate, which I find real attractive.But now, I wonder how to "translate" this C# code for component mapping into VB.NET code:
Component(x => x.Address, m =>
{
m.Map(x => x.Number);
m.Map(x => x.Street);
[code]....
what I miss is how to continue with the brackets in VB.NET, since there's no Begin End keywords or so.
EDIT 1: Following Mr. JaredPar instructions, I figured that his solution might work. If we take the time to read his answer, we may notice that we both don't know what the MType is within his solution. I might have found out that the MType is:
FluentNHibernate.Mapping.ComponentPart(Of TComponent)
Thus, TComponent is, from my understanding, an anonymous type that I shall parameter to use. From this point of view, since I wish to map the properties of my Address object, replacing TComponent in my help method signature seems not to work.
Private Sub MapAdresseHelper(Of Adresse)(ByVal a As FluentNHibernate.Mapping.ComponentPart(Of Adresse))
a.Map(Function(m) m.Number)
a.Map(Function(m) m.Street).Length(50)
[code]...
The error I get is that my Address class doesn't have a property member named Street, for instance. It sees my Address type, it recognizes it, but it seems buggy somehow. I guess VBNET is poorly designed for lambda expressions and is less evolved than C#?
View 3 Replies
Mar 10, 2010
Basically, I wish to fetch a filtered set of objects from the database (Oracle 9.2) based on the id property of the object PsalertsEvent. The code being executed is:
Public Overloads Function GetAll(ByVal laterThan As Long, ByVal filteredPsalertsEvents As IList) As IList Implements IPsalertsEventRepo.GetAll
'Get all psalerts events with an ID greater then the specified laterThan parameter
filteredPsalertsEvents = MyBase.NHibernateSession.CreateQuery("from PsalertsEvent p where p.id > " & laterThan).List
[Code]...
View 2 Replies
Jan 12, 2011
I am starting on the NHibernate world and i am experimenting with the NHibernate CookBook
recipes, i am trying to set a base entity class for my entities and this is the C# code for this. I would like to know whats the VB.NET version so i can implement it in my sample project
View 3 Replies
Nov 2, 2010
I'm writing a solution where the data entities are passed to clients using datasets through a WCF service, with nHibernate as ORM. My predecessor has written some translator classes, converting datasets to entities and vice versa. In most cases he's declared the return object as a parameter for the object.
For example:
Public Shared Function CreateEntity(ByVal ds As DataSetObject, ByVal entity As EntityObject) As EntityObject
Dim row As ds.EntityObjectRow = ds.EntityObject(0)
entity.Id = row.Id
[code]....
He's not with the company anymore, so I can't ask him why he's done it this way. Hence my question here. Is there some performance gain, or traceablity thing with nHibernate by using the first implementation rather than the latter?
View 1 Replies
Oct 26, 2010
I would like to ask if you can use VB.NET for NHibernate and Fluent Nhibernate?I have searched the web, but I can't seem to get a detailed or explicit statement that tells that one can use VB.NET for NHibernate and with Fluent.
Many of the samples in the NHibernate site are made in C#. That's why I was wondering if I can't use VB.NET when using NHibernate.
View 2 Replies
Jul 14, 2011
given this function:
Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _
[Code]....
instead of what I expected:
Select count(*) from remitline where lastname = "smith"
What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1
View 1 Replies
Nov 22, 2009
I'm struggling with getting Linq To NHibernate to work.I have referenced NHibernate, NHibernate.Linq and NHibernate.ByteCode.Castle . Also I have all other dependencies in the same folder.
Code / Error message:
Public Function GetProjectsByName(ByVal ProjectName As String) As List(Of Project)
Return (From x In _session.Linq(Of Project)() Where x.Name.Equals(Project))
End Function[code]....
... tells me that the LINQ extensions aren't loaded. Using NHibernate.Linq seems to be made in a way that it's incredibly easy to use, hence there are no tutorials on how to set it up. (Or at least I couldn't find any).
View 1 Replies
Apr 21, 2012
I am trying to learn OOD/OOP and read on the net that I am not supposed convert SQL tables into classes. But I cannot find an explanation why not to do it or which tables to skip. So I made an web application based on the below diagram. It works perfectly well. But I do not use OO. which table should not be mapped into a class and why not. do not use LINQ or NHibernate, etc as I do not understand them. I just need to understand the OOD.
View 2 Replies
Aug 9, 2010
I want to have a single table that represents a person and have a number of other tables (such as Student/Teacher) use the Person table to store information related to a person. Unfortunately the entity framework doesn't seem to like it when I try to add an association between the Student or Teacher class and I don't understand why. The Person table contains a column called ParentEntityID, which equals either a StudentEntityID or a TeacherEntityID. In an ideal world I would like to be able to reference the Person table by going Student.Person.FirstName instead of Student.Entity.Person1.FirstName. The error .Net returns when trying to connect the Student/Teacher table to the Person table is:
Error 3007: Problem in Mapping Fragments starting at lines 265, 289: Non-Primary-Key column(s) [ParentEntityID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.
The actual database I am working with is a bit more complicated and has a number of tables connected to the Entity table, which makes my object model pretty ambiguous and was hoping to be able to clean it up a bit by using the entity framework.I am using VB.Net 3.5 in a web application.
Update...In an attempt to internalize the different types of relationships I can form, I have been playing with this simple example and have come up with the following possibilities:And the reason why I cannot make an association between the Student and Address table is because that relationship is not enforced in the database. If I wanted an association between these two tables I would need to re-think the design of my database. Is that correct?
View 1 Replies
Feb 8, 2011
I have some basic expirience in Visual Basic and programming Windows Forms programs. I know now that forms programs are no longer updated by Microsoft and that WPF is the way to go. No to mention the slicker interface you can create. I've also noticed that passing SQL strings to a database is no longer the standard either. It's either Entity Framwork or Linq.
So I am going for a fresh approach. I need to develop a program that will access a sql database and be accessed by about 10 concurrent users within the office. What's the best approach in general? Linq or Entity Framework? Also, could you recommend a book or two for someone who is new to WPF and Entity Framework? I do have some programming expirience, just none with WPF or the new ways of ADO.net 4.
View 4 Replies
Feb 11, 2010
I'm using Entity Framework in Visual Studio 2010 Beta 2 (.NET framework 4.0 Beta 2). I have created an entity framework .edmx model from my database and I have a handful of many-to-many relationships.
A trivial example of my database schema is
Roles (ID, Name, Active)
Members (ID, DateOfBirth, DateCreated)
RoleMembership(RoleID, MemberID)
[Code]....
For brevity I turned the list of all the columns from the Members table into *
As you can see it's just ignoring the "Role" query.
View 2 Replies
Mar 2, 2010
I am wanting to create a Where statement within my Linq statement, but have hit a bit of a stumbling block.I would like to split a string value, and then search using each array item in the Where clause.In my normal Sql statement I would simply loop through the string array, and build up there Where clause then either pass this to a stored procedure, or just execute the sql string. But am not sure how to do this with Linq to Entity? ( From o In db.TableName Where o.Field LIKE Stringvalue Select o ).ToList()
View 5 Replies
May 4, 2012
This is my function:
Public Function GetAllEmployee() As List(Of Employees)
Return DB.Employees.Select(Function(q) New With {q.EmployeeID, q.LastName,q.FirstName}).ToList()
End Function
I'm getting an error:
Value of type System.Collections.Generic.List(Of <anonymous type>) cannot be converted to System.Collections.Generic.List(Of NorthwindModel.Employees).
View 1 Replies
Apr 20, 2009
I'm taking a peek at both the Entity Framework and LINQ to SQL, and while I like the systems (and of course the LINQ integration) I'm a little skeptical on the data-binding aspect. I've taken query results and inspected them, and they don't appear to implement the standard .NET list-binding interfaces (IBindingList, and more importantly ITypedList), leading me to believe that binding them to a grid (or anything else) is going to use reflection to get/set my entity properties. This seems like a comparatively expensive operation, especially when all of the code is generated anyway and could implement the interfaces. Is reflection used to get/set the value of the properties?
Edit: I'm actually concentrating on whether or not ITypedList is implemented somewhere along the way, as that's what has the capability to provide an explicit mechanism for defining and interacting with properties without resorting to reflection. While I didn't have a LINQ to SQL project up,I did inspect a simple Entity Framework entity query result, and it did not appear to implement ITypedList.
Edit 2: After accepting Marc's answer, I thought it might be helpful for others if I posted some simple code I used to seamlessly implement his solution. I put the following in the static constructor for my class:
public static ContextName()
{
foreach(Type type in System.Reflection.Assembly.GetExecutingAssembly()[code]....
While this is for LINQ to SQL, I'm sure an equivalent version could be written for the Entity Framework. This will scan the assembly for any types with the Table attribute and add a custom provider for each of them.
View 3 Replies
Mar 17, 2010
I've seen many examples in LINQ but i'm not able to reproduce the same result in vb.net.
I have following code: Dim context As New MyModel.Entities()
Dim rnd As New System.Random()Dim gardens As List(Of Tuin) = (From t In context.Gardens Where _
t.Approved = True And _
Not t.Famous = True _
Order By rnd.Next() _
Select t).ToList()
[Code]...
View 2 Replies
Feb 7, 2012
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.
View 1 Replies
Mar 16, 2009
I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I use NHibernate to do the work on my business entities. For example:
[code]...
However, on my User class I have some properties and collections of other objects that ideally I'd like to be lazy loaded. But of course, the ISession is created and disposed within the repository, which I guess is why, outside of that, when I try to access those properties I get a "Could not initialize proxy - no Session" error.Is my only option then to disable lazy loading when using repositories? Or is it possible (or just foolish) to somehow get the session into scope in the business layer?I do like the repository model, and NHibernate is growing on me (after lots of initial frustration trying to make it work), so what's the best way you gurus have found of using them together?
View 1 Replies
Jun 27, 2012
I can't find what's going on with the following nHibernate HQL.
here's my VB.Net code:
Return _Session.GetNamedQuery("PersonAnthroSummary").SetInt32(0, 2).UniqueResult()
My Named Query:
[code].....
View 2 Replies
Mar 16, 2009
I have an ado.net statement I want to convert to use NHibernate:
Dim sql As New StringBuilder()
sql.AppendLine("SELECT r.RoleId, r.RoleName ")
sql.AppendLine("FROM dbo.aspnet_Roles r ")
[code]...
View 1 Replies
Dec 28, 2011
I am having some redundant primary key issues.I have an Item which contains many reports. I have mapped them as shown below. I can do Session.QueryOver(Of Item).List and there are no extra columns generated. I can also do Session.QueryOver(Of Report).List and there are no extra columns generated.
However, once I try to traverse the relationship from Item to Reports, I get the SQL query shown below. Can anyone tell me why?
[Code]...
View 2 Replies
May 12, 2009
Basically I want to be able to do this:
session.ExecuteSql("...");
I don't need it to map to any entities or return any values.
View 1 Replies
Apr 28, 2009
I am getting an "ArgumentOutOfRangeException" on parameter index whenever I try to instantiate a session factory in nHibernate. The error comes from a procedure deep in the bowels of nHibernate. This is on a fresh project with a pretty simple three tier architecture. The data layer maps the nHibernate classes to simple interfaces which are implemented by the business layer.Currently there is only one interface set and mapping file being used by nHibernate. Hopefully my issue is easy to spot.
Here is the function where I build the sessionFactory.
Private Shared Function SessionFactory() As ISessionFactory
If _sessionFactory Is Nothing Then
Dim config As New NHibernate.Cfg.Configuration
config.Configure()
[code]....
Edit2: When I remove the discriminator I no longer get this error. Am I not doing that right?
Edit 3: When I download the source code for nHibernate, build it on my own, link to it's debug output and run it, I get a completely different error about ProxyFactoryFactory not being configured.
View 1 Replies
Jul 29, 2010
Because there is so little information about VB.Net and (Fluent) NHibernate to be found, I decided to write this question to all other developers finding themselves looking for more information.On of the things i had to struggle with was how to Ignore properties in NHibernate.The reason i had to ignore properties was because we used a Webserivce which cannot serialize Interface classes (ILists). Which are used a lot with NHibernate.
View 1 Replies
Dec 21, 2010
Well i have been fighting with this for a little bit now, and i can't seem to find a solution for something it should be really simple. I got a class ( really simple class ) i got the hbm.xml ( SET AS EMBEDDED RESOURCE ) i got the config file set for SQLite but i still get the [Class] Is not mapped.Here is where the error comes up, when i run this:
Public Sub LoadCentersFromDatabase()
Try
Dim session As ISession = OpenSession()
Dim query As IQuery = session.CreateQuery("from Center")
[code]....
View 1 Replies
Jul 9, 2010
I've been using c# for the past year and I enjoy the power you get with Fluent NHibernate. One question that I get from friends is "nice but how can vb.net programmers use this?"So for example- the below is a c# mapping class. How would someone do this with vb.net?
public class PostMap : ClassMap<post>
{
public PostMap()
{
Table("Posts");
[Code]...
View 1 Replies
Jan 22, 2012
I am attempting to bind objects pulled from an NHibernate session to a DataGridView and am having problems.I have a single session in which I fetch all of my "look-up" items that are bound to a combobox column, and then I query for the objects themselves. omehow, this still results in proxy child objects on the main objects. I have even changed the mapping of the look-up items to eager fetch, but I still get proxies somehow.Here is how I am fetching the objects:
Dim _makes As IList(Of Make) = session.QueryOver(Of Make).List
Dim _models As IList(Of Model) = session.QueryOver(Of Model).List
Dim _cars as IList(of Car) = session.QueryOver(of Car).List
[code].....
View 1 Replies
Oct 5, 2010
Question: I get an exception serializing this class to a nHibernate xml file ({"Could not determine type for: System.Drawing.Image, System.Drawing, for columns:NHibernate.Mapping.Column(Settings)"}).
using System;
using System.Collections.Generic;
using System.Text;
[code].....
View 3 Replies
Feb 12, 2010
Instinctively, I would say that this is impossible, as NHibernate needs to know some mapping information on how to persist a given type. Thus, I encountered some situations in which I could use such a feature. For instance, through a named query or something like so. On the other hand, using a named query would require me to make an addition to the configuration file.
Let's suppose we have an application interacting with some underlying datastore. This datastore is configured through the NHibernate configuration file. Then, I wish to have NHibernate load only a subset of an entity properties, from another subsystem to which my application shouldn't need to interact much, so it is not worthy to define classes for this system, as I only need a fraction of this alien system's information, let's say three out of thirty-two data columns. For that matter, if I chose to load only those three columns let's say for performance concerns, I would then use an anonymous type, perform the required action onto this information, then persist it back to the datastore. Now, it wouldn't be of much interest to do so if I only had one entity to get loaded from the datastore, so let's say I have about 75,000 rows to load into my process. I then shall consider this subset option very seriously!
What strategy should you choose in such situation, if you needed to persist these changes to a subset only of this entity's properties?FYI: I am asking because I must write specific rules of usage with NHibernate, such rules that even a beginner developer would even be able to use it without knowing too much about NHibernate, but only following the rules and guidance of the technical documents I have to produce.
View 1 Replies
Dec 6, 2011
I am using Fluent NHibernate to map an Oracle database. It is a legacy database so I cant really change everything I want.There is a GUID field, but the keys are still composite (I will change this as soon as I can so that the keys are not composite, but I cant do it right now). The GUID is a VARCHAR2 field with this layout: 551608b1-275d-49f6-9561-44d01aacf23f. The GUID is not added by a sequence in Oracle, but inserted from code (C# or VB.net)[code]Is the problem that I dont use a sequence to generate my GUID? How can I overcome this?
View 1 Replies