views:

53

answers:

0

I'm creating my generic DataContext using only the connectionString in the ctor. I have no issues in retrieving the table using DataContext.GetTable(). However, I need to also be able to retrieve entities of inline table functions. The dbml designer generates

public IQueryable<testFunctionResult> testFunction()
    {
        return this.CreateMethodCallQuery<testFunctionResult>(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
    }

The question is how do I get the MethodInfo.GetCurrentMethod() when the DataContext has no method called "testFunction", i.e.typeof(DataContext).GetMethod("testFunction") returns null?

What I'm trying to achieve is something like:

        public class UnitofWork<T>
    {
     public UnitofWork(string connectionString)
     {
        this.DataContext = new DataContext(connectionString);
     }

     public UnitofWork(IQueryable<T> tableEntity)
     {
         _tableEntity = tableEntity;
     }

     public IQueryable<T> TableEntity
        {
            get
            {
            if (DataContext == null)
                return _tableEntity;

            var metaType = DataContext.Mapping.GetMetaType(typeof (T));

            if (metaType.IsEntity)
                _tableEntity = DataContext.GetTable<T>();
            else
            {
                var s = typeof(T).Name;
                string methodName = s.Substring(0, s.IndexOf("Result")) + "()"; // the designer automatically affixes "Result" to the type name

                // Make a method from methodName
                // _tableEntity = DataContext.CreateMethodCallQuery(DataContext, method, new object[]{});
            }

            return _tableEntity;
            }
            set { _tableEntity = value; }
        }
    )

Thanks in advance for any insight
Jeremy