Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to Azure Search

I'm creating a class that gonna work with Azure Search service. I want it to accept LINQ expressions for searching documents so outer modules dont know the Azure Search syntax.

  1. Is there a library that can implement it? As the Azure Search is quite young, i was unable to find such one on the Internet. All i've found is RedDog package that is pretty good but still needs field names and comparison operations as strings that some day will definitely become "magic".

  2. Okay, Azure Search also accepts OData formatted queries. I've seen few OData-query-to-LINQ-expression solutions but none that does the contrary. I need a library that can translate LINQ to OData string.

Any help is appreciated.

like image 455
LINQ2Vodka Avatar asked Sep 17 '14 22:09

LINQ2Vodka


3 Answers

For OData services, you can choose to use .NET client for OData or code generator for OData which have great support of LINQ. You can refer here to know detail about how to use OData Client Generator to generate client-side proxy class and then use LIQN easily to do all queries you need. And OData Client Generator is built on top of OData Client for .NET, and I recommend that you can just start with code generator.

But please be noted that these two libraries are both for OData V4 only. If you use older OData versions, you cannot use code generator but use "Add Service Reference". And then you can also easily using LINQ for your queries.

Hope this can help you out.

like image 173
QianLi Avatar answered Oct 16 '22 17:10

QianLi


You can try my GitHub project here:

https://github.com/ubergeoff/HollowPoint.Azure

Example:

HollowPoint.Azure.DbTable<People> tt = new HollowPoint.Azure.DbTable<People>();

var filter = tt.Query()
.Where(t => t.Age >= 16 && t.Age < 33)
.ToODataString();    

Will output OData format string of:

((Age ge 16) and (Age lt 33))
like image 29
UberGeoff Avatar answered Oct 16 '22 18:10

UberGeoff


I have just released a toolkit for Azure Search which also includes a LINQ provider. The package is named AzureSearchToolkit and is available as a NuGet https://www.nuget.org/packages/AzureSearchToolkit.

You can also check out the source on https://github.com/nkovacic/AzureSearchToolkit.

like image 1
Niko Kovačič Avatar answered Oct 16 '22 19:10

Niko Kovačič