Skip to content

LazyEntityGraph is an open source library for .NET which lets you generate object graphs with circular dependencies, such as those found in ORMs, by lazily generating relationship properties.

License

Notifications You must be signed in to change notification settings

dbroudy/LazyEntityGraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status NuGet version

LazyEntityGraph

LazyEntityGraph is the successor to AutoEntityFramework. This project aims to both improve upon the functionality of the original, and open the door to integration with other test object creators and ORMs.

What's New?

The key benefits of LazyEntityGraph over AutoEntityFramework are:

  • Extensible architecture: AutoFixture and Entity Framework integration is available through extensions; similarly it would be possible to create extensions for NHibernate, ObjectHydrator, etc
  • Constrained relationships: Specify one-to-one, one-to-many or many-to-many relationships between entities and the generation process will respect those relationships
  • Entity Framework integration: Automatically generate model metadata from EDMX or Code First DbContexts, including foreign keys

For documentation, see this wiki page

Objective

When writing tests, we often need to create test objects without necessarily caring about the data used to populate them. There are many projects which accomplish this in .NET, among them AutoFixture, ObjectHydrator, NBuilder and more.

Also popular in the .NET world are ORMs: libraries used to bridge the gap between data and code by representing relational data as C# objects. The most popular of these are Entity Framework and NHibernate. These produce graphs of classes linked by relationship properties.

public class Order
{
  public int Id { get; set; }
  public virtual ICollection<Product> Products { get; set; }
}

public class Product
{
  public int Id { get; set; }
  public virtual ICollection<Order> Orders { get; set; }
}

However, if you are using a test object creation library like AutoFixture, you will run into a problem when trying to create an instance of the Order class above: the circular reference between Product and Order.

When using the ORM to retrieve one of these objects, you typically don't want to retrieve the entire object graph...! For this reason, relationship properties are often marked virtual, to enable them to be lazy-loaded.

So, we come to the purpose of this library: to permit test object creation tools like AutoFixture to create entity graphs with circular references.

About

LazyEntityGraph is an open source library for .NET which lets you generate object graphs with circular dependencies, such as those found in ORMs, by lazily generating relationship properties.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages