Is there an easier way to create a WCF / OData data service query provider?

I have a simple small data model resembling the following:

InventoryContext {

IEnumerable<Computer> GetComputers()

IEnumerable<Printer> GetPrinters()

}

Computer {

public string ComputerName { get; set; }

public string Location { get; set; } }

Printer {

public string PrinterName { get; set; }

public string Location { get; set; }

}

The results come from a non-SQL source, so this data does not come from the Entity Framework connected to the database.

Now I want to provide data through the WCF OData service. The only way I've found to do so far is to create my own data service query provider on this blog:

http://blogs.msdn.com/alexj/archive/2010/01/04/creating-a-data-service-provider-part-1-intro.aspx

... , , . 4 .

- Entity Framework ? , - - , WCF , ?

+5
3

.

InventoryContext :

IQueryable<Computer> Computers { get { return GetComputers().AsQueryable(); } }
IQueryable<Printer> Printers { get { return GetPrinters().AsQueryable(); } }

( System.Data.Services.Client ):

using System.Data.Services.Common;

[DataServiceKey("ComputerName")]
public class Computer 
{
    public string ComputerName { get; set; }
    public string Location { get; set; } }
}

[DataServiceKey("PrinterName")]
public class Printer
{
    public string PrinterName { get; set; }
    public string Location { get; set; } }
}

, InventoryContext, :

public InventoryDataService : DataService<InventoryContext>
{
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        config.UseVerboseErrors = true;         
    }
}

, . InventoryContext .

+1

" ". , ( ), IQueryable (T - ). "", . http://msdn.microsoft.com/en-us/data/cc745968.aspx

+2

WCF.

Microsoft OData, Entity Framework.

, OData Mongo DB.

http://channel9.msdn.com/events/MIX/MIX11/FRM16

Code is also available at codeplex http://wcfdstoolkit.codeplex.com/

Hope this helps.

0
source

All Articles