markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 303 forks source link

Accessing Simple.Data Table with Schema name throws error #306

Open aamirhabibkhan opened 10 years ago

aamirhabibkhan commented 10 years ago

I am using Simple.Data for Oracle version 0.18.3.1 in an Asp.Net MVC 4 application. It works fine with tables which dont precede by schema name but crashes when I try to get data from a table which MUST be preceded schema name. The error I receive is

"No matching table found, or insufficient permissions."

The query I need to execute is as follow:

SELECT * FROM SchemaName.TableName

This query works fine when I try to execute it in Oracle Sql Developer. I get results. But get above error using Simple.Data in C#. I have tried the following ways:

//BASE CLASS
public class BaseRepository
{
    protected dynamic DB { get; set; }
    public BaseRepository()
    {
        DB = Database.OpenNamedConnection("intranet_db");
    }
}

//Derived Class
public class EmployeeRepository : BaseRepository
{
    public List<Employee> GetEmployees()
    {                
         List<Employee> employees =     DB.SchemaName.TableName.FindAllBy(JoinedOn:"2009-05-31");

        // I also have tried the following combinations as specified in documentations
        // DB.SchemaName["TableName"].FindAllBy(JoinedOn:"2009-05-31");
        // DB["SchemaName"].TableName.FindAllBy(JoinedOn:"2009-05-31");
        // DB["SchemaName"]["TableName"].FindAllBy(JoinedOn:"2009-05-31");

        return employees;
    }
}

but it keeps throwing the above mentioned error. By looking at the following stack trace, I see that it does not searches for the table name in proper schema and therefor throws "Not Found" exception. May be I am wrong. Can you please help me resolve this issue ASAP???? I am badly stuck.

The following is the Stack Traces of the main exeption and its InnerException.

STACK TRACE

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Simple.Data.SimpleQuery.TryConvertToGenericCollection(ConvertBinder binder, Object& result, Type collectionType) at Simple.Data.SimpleQuery.TryConvert(ConvertBinder binder, Object& result) at CallSite.Target(Closure , CallSite , Object ) at MyProject.Repository.Repositories.EmployeeRepository.GetStoppedEmployees() in d:\Projects.Net\MyProject\MyProject.Repository\Repositories\EmployeeRepository.cs:line 11 at MyProject.Web.Controllers.HomeController.Index() in d:\Projects.Net\MyProject\MyProject.Web\Controllers\HomeController.cs:line 17 at lambdamethod(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass42.b41() at System.Web.Mvc.Async.AsyncResultWrapper.<>cDisplayClass8`1.b7(IAsyncResult ) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass37.<>cDisplayClass39.b33() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass4f.b__49()

INNER EXCEPTION STACK TRACE

at Simple.Data.Ado.Schema.TableCollection.Find(String tableName, String schemaName) at Simple.Data.Ado.Schema.TableCollection.Find(ObjectName tableName) at Simple.Data.Ado.Schema.DatabaseSchema.FindTable(ObjectName tableName) at Simple.Data.Ado.QueryBuilderBase.SetQueryContext(SimpleQuery query) at Simple.Data.Oracle.OracleQueryBuilder.Build(SimpleQuery query, IEnumerable1& unhandledClauses) at Simple.Data.Oracle.OracleCustomQueryBuilder.Build(AdoAdapter adapter, Int32 bulkIndex, SimpleQuery query, IEnumerable1& unhandledClauses) at Simple.Data.Ado.QueryBuilder.Build(SimpleQuery query, IEnumerable1& unhandledClauses) at Simple.Data.Ado.AdoAdapterQueryRunner.GetQueryCommandBuilders(SimpleQuery& query, IEnumerable1& unhandledClauses) at Simple.Data.Ado.AdoAdapterQueryRunner.RunQuery(SimpleQuery query, IEnumerable1& unhandledClauses) at Simple.Data.Ado.AdoAdapter.RunQuery(SimpleQuery query, IEnumerable1& unhandledClauses) at Simple.Data.DatabaseRunner.RunQuery(SimpleQuery query, IEnumerable`1& unhandledClauses) at Simple.Data.SimpleQuery.Run() at Simple.Data.SimpleQuery.Cast[T]()

jdscolam commented 10 years ago

I am having this issue as well. Is anyone looking at this?

aamirhabibkhan commented 10 years ago

I dont think so. This issue is open for almost 2 months now but nobody has replied. I quit using Simple.Data for Oracle and am now using simple ADO.NET. I think Simple.Data should only be used for SQL Server. Other plugins are not so mature.

markrendle commented 10 years ago

This is on my radar, I'm just juggling a lot of things right now.

jdscolam commented 10 years ago

Thanks for looking into this Mark!

jdscolam commented 10 years ago

To add some flavor here, I have manually created a work around that relies on brute forcing a schema into the provider, then resetting the adapter so the new schema is picked up. This works well in a synchronous environment, but when called by two ajax calls in quick succession one of the schemas "wins" so the other query fails. The final solution needs to account for this sort of async calling.