I have a database table with many lookup tables:
OrderType ShippingType etc.
My order table refers to each of these tables:
Order OrderID OrderTypeID ShippingTypeID
I am using Entity Framework as a data access layer. I have a page that should display order information. I'm struggling to find the best / right way to use these objects.
My page should display data such as:
Order No. 1000000
Shipping Type: UPS
Order Type: Online
Etc Type: Etc.
Is it better to create a view in the database that returns the data I need and then add it to my entity model and just use it directly so that I don't have to write joins in my queries? Or it is better to create an intermediate class as follows:
class OrderView { public int OrderNumber { get; set; } public string OrderType { get; set; } public string ShippingType { get; set; } } var order = from o in db.Orders join ot in db.OrderTypes on o.OrderTypeID equals ot.OrderTypeID join st in db.ShippingTypes on o.ShippingTypeID equals st.ShippingTypeID select new OrderView { OrderNumber = o.OrderNumber, ShippingType = st.Description, OrderType = ot.Description };
What is the best way here?
source share