Linq Composite Object Return From Logic

I am trying to break down the architecture into three independent layers Data/Logic and App (Web/Service/Application/WS)

As posted on my previous question http://www.experts-exchange.com/Programming/Languages/.NET/LINQ/Q_25355958.html

I have now set up my objects in ABC.Data and my DataContext in ABC.Logic

However, what I am running in to is that I can only return objects in my ABC.Data library.

How do I handle selecting Customer Information as well as other columns relevant to the query and returning it to the APP layer without having to create classes?

Example:
// I CANT RETURN A LIST OF CUSTOMER AND STATE INFO LIKE SPECIFIED IN THE QUERY
public List<Test1.Logic.Customer> GetCustomerByStateName(String StateName)
        {
            Test1.Logic.DataClasses1DataContext db = this;
            return (
                    from c in db.Customers
                    join cl in db.CustomerLocations on c.CustomerId equals cl.CustomerId
                    where cl.USState.USStateAbbr == StateName
                    select c, cl
                ).ToList<Test1.Logic.Customer>();
        }



Hope this explains what I am trying to do.
Thanks
Smit.
LVL 12
ullfindsmitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard LeeSoftware EnthusiastCommented:
Interesting questions. Firstly you should probably create class/lightweight entities specific to your domain model and pass those around. Your query should be a little bit more specific to the business requirement rather than so generic.

To answer your question however you could try:

Set your return to to object and return an anonymous type would your Customer as one of the properties and the other columns as other properties.

object GetData()
{
   // Perform your query
   var result = ...

   return new {
      Customer = result.Customer,
      X = result.X,
      Y = result.Y
   };
}

You will of course have to interrogate this type in the client using reflection otherwise you cannot get access to the contents as you cannot cast to the anonymous type.

Is this maintainable - no? however it solves the problem.

DaTribe
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LabelsoftCommented:
I got around architectural problems like this by utilizing transfer objects. These are simple classes tailer made to meet the needs of the business logic. It's part of the DAO pattern design, which you can read about here:

http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
0
ullfindsmitAuthor Commented:
DaTribe I ended up extending all the data objects in my logic library so I can add additional fields without having to read create the base fields from DB.

Labelsoft, what you are recommending is what we are trying to get away from. The system is overengineered for what it is needed for. The amount of time needed to make a simple change is significantly higher in creating these layers that in our case dont really serve a purpose.

Thank you for your time.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.