2

I need to select from varying levels of reporting department tables, i.e. Dept1, Dept2, Dept3, ect. [1] depending on which reporting level the user chooses. How can I dynamically express the 'table' to select from based on a given string parameter, which is the table name?

[1] Easy points (lets talk) for anyone that can help me out of this, deeper mess than the question exposed.

BREAKING NEWS: Looks like I'm going with a 'switch/case' construct. I'm tired of poring over idiotic non-solutions, and the first intelligent one I found doesn't work easily enought (without generations monastic, secluded dedication). The customer's needs come before mine.

3
  • That's a really bad way to organize data, but I suspect you're getting to understand that now. Commented Sep 19, 2009 at 16:15
  • 1
    I've understood that since college, but I can't always use my own designs from the word go. :-( Commented Sep 19, 2009 at 17:18
  • -1 for unnecessary vitriol and attempted clever phrasings. Stick to the point, please. Commented Jan 11, 2011 at 0:51

2 Answers 2

1

I don't believe the EF has an equivalent of Linq->SQL's GetTable yet although I did find this post about a possibly future implementation of GetEntitySet as well as a simple implementation you can use I would check it out.

Sign up to request clarification or add additional context in comments.

1 Comment

There is one good candidate solution on that post, drowning in a black sea of utter stupidity and density such as only seen in radioactive metals.
0

Do you have the ability to change the schema? I suspect you are asking this question because you don't, but if you do, it might be easier to have a Department table which defines a department name and its ID. Then, you can have a single table with the entities you are searching for and a foreign key pointing to a department.

So, if the entities you are trying to query are employees, your tables might look like this:

Department
------------
ID     int
Name   text

Employee
--------------------
ID             int
Name           text
DepartmentID   int

Then your query might look something like this:

var Employees = from emp in db.Employee.Include("Department")
                where emp.Department.Name == "Sales"
                select emp;

1 Comment

I can change the schema, but only later, with an incremental rewrite. I can't change it today to solve this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.