Had enough of all those cast from int to enums when using Entity Framework? Do not trust the user of your entities with the collections? Wrap them with safer/better abstractions and use the EFWrappableFields library to support these wrapped properties in all expressions.
C#
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
EF1Test
EF4Test
EntityFrameworkFieldsWrapper.EF1
EntityFrameworkFieldsWrapper.EF4
libs
.gitignore
EFExtensions.EFWrappableFields.sln
README.md
generate_release.ps1

README.md

Entity Framework Wrappable Fields

Entity Framework has some limitations in what can be queried and what types can be mapped.

I created this extension to allow any property to be wrapped by a property not defined in the edmx mapping.

There are several usages for this extension, you could us this to add enums to your entities or to protect the relations using types with less actions or properties available.

For more details of this extension see:

Usage

To use the Wrappable Fields extension, add a reference to the assembly, and in the place were you would normally start with filtering your EntitySet/ObjectQuery/IQueryable you have to wrap that collection with a WrappedFieldsObjectQuery object.

So what used to be:

var context = new EFTestDatabaseEntities();
var orders = from o in context.Orders
   where o.Status == OrderState.Shipped
   select o;

Now has to become:

var context = new EFTestDatabaseEntities();
var orders = from o in new WrappedFieldsObjectQuery<Order>(context.Orders)
   where o.Status == OrderState.Shipped
   select o;

While this looks like a big impact, you should really model your application such that you aren't writing these queries everywhere.

In order for this to work the library tries to find if there is a Property with a Db prefix for the property used and replaces it. So the DbStatus is in the entity model but hidden, and the Status field is the public visible property.

Developing

If you want to fork this project and add some feature, use the EF1Test/TestDatabase.sql script to generate and fill the database and correct the connection string if needed.