While reading through some comments on a discussion forum, I noticed a discussion about EF Core. They were talking about a specific feature that was missing(canāt remember the feature).
My answer was to try NHibernate but I know that the learning curve is quite steep. Another person on the forum suggested XPO (eXpress Persistent Objects), a free(!) ORM from DevExpress.
From the site:
eXpress Persistent Objects (XPO) is an Object-Relational Mapping (ORM) tool that handles all aspects of database creation and object persistence, allowing you to concentrate on your application's business logic rather than database complexities. It offers Code First, Model First and Database First development workflows.
Getting started
- Install the DevExpress XPO nuget package:
dotnet add package DevExpress.Xpo
Create a new class that inherits from
XPLiteObject or XPObject:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Product : XPLiteObject { | |
public Product(Session session) | |
: base(session) { | |
} | |
Guid key; | |
[Key(true)] | |
public Guid Key { | |
get { return key; } | |
set { SetPropertyValue(nameof(Key), ref key, value); } | |
} | |
string description; | |
[Size(255)] | |
public string Description { | |
get { return description; } | |
set { SetPropertyValue(nameof(Description), ref description, value); } | |
} | |
} |
- Configure the XPO data layer:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XpoDefault.DataLayer = XpoDefault.GetDataLayer(connectionString, AutoCreateOption.DatabaseAndSchema); |
- Create a unit of work and execute a query:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var uow = new UnitOfWork()) { | |
var products = uow.Query<Product>() | |
.Select(p => $"{p.Description}"); | |
foreach (var productDescription in products) { | |
Console.WriteLine(productDescription); | |
} | |
} |