Development With A Dot

Blog on development in general, and specifically on .NET

ADO.NET Data Services and NHibernate

With the arrival of the LINQ provider for NHibernate, NHibernate now supports ADO.NET Data Services. There are some restrictions, however:

  • Relations must be entities or simple collections of entities (Entity, IList, IList<T>), not sets (ISet<T>, HashSet<T>) or maps (IDictionary, IDictionary<K, V>, HashTable);
  • The ID property must be called either "ID", or end with "ID", for example, CustomerID;
  • The ID property must have a public setter as well as a public getter;
  • The ID property must be of a base type, such as int or string;
  • The collections to expose must be properties of type IQueryable<T> or IOrderedQueryable<T>.

Here is an example:

public class Customer

{

    public virtual Int32 ID

    {

        get;

        set;

    }

    public virtual IList<Orders> Orders

    {

        get;

        private set;

    }

}

public class CustomersOrdersContext: NHibernateContext

{

    public CustomersOrdersContext()

    {

    }

    public CustomersOrdersContext(ISession session): base(session)

;nbsp;   {

    }

    public IOrderedQueryable<Orders> Orders

    {

        get

        {

            return(this.Session.Linq<Orders>();

        }

    }

    public IOrderedQueryable<Customers> Customers

    {

        get

        {

            return(this.Session.Linq<Customers>();

        }

    }

}

And, on the ADO.NET Data Services class:

[ServiceBehavior(IncludeExceptionDetailsInFaults = true)] 

public class CustomersOrdersDataService: DataService<CustomersOrdersContext>

{

    public static void InitializeService(IDataServiceConfiguration config)

    {

        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);     } }

The IncludeExceptionDetailsInFaults helps debugging any exceptions that may occur, you should remove it in production code.

Bookmark and Share

Comments

Twitter Trackbacks for ADO.NET Data Services and NHibernate - Development With A Dot [asp.net] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 ADO.NET Data Services and NHibernate - Development With A Dot         [asp.net]        on Topsy.com

# October 15, 2009 6:59 AM

ADO.NET Data Services and NHibernate :The Spirit of Humppa said:

Pingback from  ADO.NET Data Services and NHibernate :The Spirit of Humppa

# November 21, 2009 5:13 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)