Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Fixes...
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Jul 17, 2013
1 parent 0598405 commit 2c70419
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
4 changes: 2 additions & 2 deletions InterLinq/IQueryHandler.cs
Expand Up @@ -15,14 +15,14 @@ public interface IQueryHandler
/// </summary>
/// <param name="type">Type of the returned <see cref="IQueryable{T}"/>.</param>
/// <returns>Returns an <see cref="IQueryable{T}"/>.</returns>
IQueryable Get(Type type);
//IQueryable Get(Type type);

/// <summary>
/// Returns an <see cref="IQueryable{T}"/>.
/// </summary>
/// <typeparam name="T">Generic Argument of the returned <see cref="IQueryable{T}"/>.</typeparam>
/// <returns>Returns an <see cref="IQueryable{T}"/>.</returns>
IQueryable<T> Get<T>() where T : class;
//IQueryable<T> Get<T>() where T : class;

/// <summary>
/// Returns an <see cref="IQueryable{T}"/>.
Expand Down
38 changes: 27 additions & 11 deletions InterLinq/InterLinqQueryHandler.cs
Expand Up @@ -24,17 +24,24 @@ public abstract class InterLinqQueryHandler : IQueryHandler

#endregion

#region IQueryHandler Members

#region IQueryHandler Members

private Dictionary<Type, MethodInfo> genericMethodsCache1 = new Dictionary<Type, MethodInfo>();
/// <summary>
/// Returns an <see cref="IQueryable{T}"/>.
/// </summary>
/// <param name="type">Type of the returned <see cref="IQueryable{T}"/>.</param>
/// <returns>Returns an <see cref="IQueryable{T}"/>.</returns>
public IQueryable Get(Type type)
{
MethodInfo getTableMethod = GetType().GetMethod("Get", new Type[] { });
MethodInfo genericGetTableMethod = getTableMethod.MakeGenericMethod(type);
MethodInfo genericGetTableMethod;

if (!genericMethodsCache1.TryGetValue(type, out genericGetTableMethod))
{
MethodInfo getTableMethod = typeof (InterLinqQueryHandler).GetMethod("Get", new Type[] {});
genericGetTableMethod = getTableMethod.MakeGenericMethod(type);
genericMethodsCache1.Add(type, genericGetTableMethod);
}
return (IQueryable)genericGetTableMethod.Invoke(this, new object[] { });
}

Expand Down Expand Up @@ -66,20 +73,29 @@ public virtual bool StartSession()
public virtual bool CloseSession()
{
return true;
}

}

private Dictionary<Type, MethodInfo> genericMethodsCache2 = new Dictionary<Type, MethodInfo>();
/// <summary>
/// Returns a <see cref="IQueryable{T}"/>
/// </summary>
/// <param name="type">Generic Argument of the returned <see cref="IQueryable{T}"/>.</param>
/// <param name="name">The name of the query.</param>
/// <param name="parameters">Parameters for the quey.</param>
/// <returns>Returns a <see cref="IQueryable{T}"/>.</returns>
public virtual IQueryable Get(Type type, string name, params object[] parameters)
{
MethodInfo getTableMethod = GetType().GetMethod("Get", new Type[] { typeof(Type), typeof(string), typeof(object[]) });
MethodInfo genericGetTableMethod = getTableMethod.MakeGenericMethod(type);
return (IQueryable)genericGetTableMethod.Invoke(this, new object[] { type, name, parameters });
public virtual IQueryable Get(Type type, string name, params object[] parameters)
{
MethodInfo genericGetTableMethod;

if (!genericMethodsCache2.TryGetValue(type, out genericGetTableMethod))
{
MethodInfo getTableMethod = typeof(InterLinqQueryHandler).GetMethod("Get", new Type[] { typeof(string), typeof(object[]) });
//MethodInfo getTableMethod = typeof(InterLinqQueryHandler).GetMethods().FirstOrDefault(x=>x.Name=="Get" && x.IsGenericMethod && x.GetParameters().Count()==2);
genericGetTableMethod = getTableMethod.MakeGenericMethod(type);
genericMethodsCache2.Add(type, genericGetTableMethod);
}

return (IQueryable)genericGetTableMethod.Invoke(this, new object[] { name, parameters });
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions Testing/InterLinq.Tests/Client/MockClientContext.cs
Expand Up @@ -39,22 +39,22 @@ private static InterLinq.IQueryRemoteHandler GetMockServerQueryHandler()

public IQueryable<Entities.Supplier> Suppliers
{
get { return this.QueryHandler.Get<Entities.Supplier>(); }
get { return this.QueryHandler.Get<Entities.Supplier>(null, null); }
}

public IQueryable<Entities.Customer> Customers
{
get { return this.QueryHandler.Get<Entities.Customer>(); }
{
get { return this.QueryHandler.Get<Entities.Customer>(null, null); }
}

public IQueryable<Entities.Product> Products
{
get { return this.QueryHandler.Get<Entities.Product>(); }
{
get { return this.QueryHandler.Get<Entities.Product>(null, null); }
}

public IQueryable<string> Digits
{
get { return this.QueryHandler.Get<string>(); }
{
get { return this.QueryHandler.Get<string>(null, null); }
}

public IQueryable<Entities.Customer> CustomersByCity(string cityName)
Expand Down

0 comments on commit 2c70419

Please sign in to comment.