Lightweight alternatives to NHibernate

后端 未结 8 1888
感情败类
感情败类 2021-01-01 17:54

NHibernate is not really a good fit for our environment due to all the dependencies. (Castle, log4net etc.)

Is there a good lightweight alternative?

Support

相关标签:
8条回答
  • 2021-01-01 17:58

    For a lightweight ORM that performs well and only requires a single assembly why not try out Lightspeed from Mindscape. It's not open-source, however source is available and it's reasonably priced - the risk with most ORM's that aren't well adopted is of course quality and level of support, and there are very few other open source ORM's worth bothering with in the .Net space at the moment.

    Because of your dislike of NHibernate's dependencies it sounds like you don't have a need for a logging framework or any of the castle project facets i.e. IoC, Monorail etc. Have you considered maybe just taking the bare minimum of NHibernate requirements (log4net and the Iesi collections I believe, and dynamic proxy from the castle project?) and running ILMerge over them to consolidate them into a single assembly - might take a bit of fiddling, but it's not too hard - or alternatively you could just pull the source code for each of these projects into a custom build of NHibernate you maintain for your organization that trims out the features not required by your project/organization - it's not as hard/akward as it sounds and I've done something along these lines for one project where we wanted to benefit of an ORM, but needed to reduce the size of the distributed files/installer.

    Also - are you perhaps able to explain what you feel is too "heavy" about an Nhibernate based solution ... in my experience its a reasonably lightweight ORM framework compared to some.

    0 讨论(0)
  • 2021-01-01 17:58

    some of the alternatives:
    - ActiveRecord - it uses nhibernate.dll in background, but configuration is done through attributes. It's like lite version of nhibernate
    - Subsonic
    - CoolStorage.NET - I used it a lot with small projects. Works well with number of dbs

    0 讨论(0)
  • 2021-01-01 18:02

    Adding to this list, you could also have a look at Dapper (written for and used by StackOverflow itself).

    0 讨论(0)
  • 2021-01-01 18:03

    Massive - https://github.com/robconery/massive

    or

    PetaPoco - https://github.com/toptensoftware/petapoco

    Both are a single .cs file with no dependencies except what's in the GAC.

    (full disclosure, PetaPoco is something I wrote)

    0 讨论(0)
  • 2021-01-01 18:05

    If you don't need fully-functional ORM and just need fast database independent data layer over ADO.NET try out open-source NI.Data library (V2). It is very lightweight (just one small assembly, no other dependencies), provides all standard data layer infrastructure:

    • query abstraction and parser for its string representation called 'relex' (it looks like: "books(rating=5)[title,id]" - very good alternative to Linq-to-SQL and expressions can be composed on the fly )
    • 'view' concept for encapsulating complex DB-syntax dependent SQL queries
    • data triggers
    • data layer permissions for select/update/delete queries
    • from the box supports MS SQL, SQLite, MySQL, Odbc/OleDb providers (MS Access). Support for other SQL databases could be easily added.

    Its main component (DALC) initialized just with one line of code:

    var dalc = new DbDalc(new SqlClientDalcFactory(), connectionStr);
    

    that's all. If you need .NET 2.0 runtime support you can try to compile either latest V2 version under 2.0 runtime or use previous legacy version (NI.Data.Dalc, V1).

    0 讨论(0)
  • 2021-01-01 18:09

    LINQ to SQL could be good alternative to "heave" ORM systems if you'll use it properly.

    0 讨论(0)
提交回复
热议问题