[en] What about Linq on the server? (solved)

Topics: Technical Support
Sep 10, 2011 at 4:59 PM

Hi !

I saw the sample with linq, but this is on the client!

I am looking for something like this:

var proxy = conn.CreateProxy<Expression>();
Result<some> r = proxy.Query(from item in ServerItems where item.Name = "Test" select item);

Naturally, no question, client and server must know tese types.

Thanks so far and
best regards,

++mabra

Coordinator
Sep 12, 2011 at 7:12 PM
Edited Sep 12, 2011 at 7:16 PM

Hi mabra,

Zyan has full support for server side executed LINQ queries since Release 2.1.
Please have a look at What´s new in Zyan (Please scoll down to the headline What´s new in Zyan 2.1?)

You can publish IEnumerable<T> or IQueryable<T> as properties or method return values in your server components.
With Zyan you can publish Entity Framework, LINQ2SQL or custom LINQ-DataSources easily in a distributed application.

You can find a fully functional distributed LINQ example in Zyan Source code folder examples\Zyan.Examples.Linq (http://zyan.codeplex.com/SourceControl/changeset/view/12976#245805)

Example:

 

// shared
interface ICustomerService
{
    IQueryable<T> Query<T>() where T : class;
}

// server
public class CustomerService
{
    public IQueryable<T> Query<T>() where T : class
    {
        if (typeof(T) == typeof(Customer))
	{
	    return DataAccess.Customers.AsQueryable();
        }

	if (typeof(T) == typeof(Address))
	{
	    return DataAccess.Addresses.AsQueryable();
	}

	throw new NotSupportedException(string.Format("Type {0} is not supported", typeof(T).Name));
    } 
}


// client
using (var connection = new ZyanConnection(url))
{
	var proxy = connection.CreateProxy<ICustomerService>();
	var query =
	    from c in proxy.Query<Customer>()
	    where c.BirthDate > DateTime.Today.AddYears(-18)
	    select c;
	...
}


Sep 15, 2011 at 9:10 PM

Hello Rainbird !

Thanks, I see, I have not understand the code :-(

Is "query" above finally an expression, which will be serialized?
I thought, if you write "proxy.Query..." this is finally the remote part and the rest of the code executes locally.

I run'ed that sample already ... will build a variant, to see, if it good as a query engine for my [remote] cache
and how fast this runs.

Zyan seem be to really gret for me!

Thanks so far and
best regards,

++mabra

Coordinator
Sep 19, 2011 at 9:38 PM

Hello mabra,

> Is "query" above finally an expression, which will be serialized?

Yes. Zyan serializes the expression tree of the LINQ query. The query is truly executed on the server. The result is serialized and then sent back to the client.

> I thought, if you write "proxy.Query..." this is finally the remote part and the rest of the code executes locally.

No, the entire query is executed server side. Zyan internally uses the InterLinq project (InterLinq code is compiled into Zyan assemblies) to accomplish this.
Zyan make distributed LINQ queries as easy as local ones, because of its good and transparent integration.

> .. will build a variant, to see, if it good as a query engine for my [remote] cache and how fast this runs.

Should be no problem.

> Thanks, I see, I have not understand the code :-(

Do you have further questions?

 

Rainbird