Datinhkhach
New Member
Simplified Example for simplicities sake.I am building a calculator for an online store, however product prices are as a percentage of a calculated base price.As such, I have 3 Tables...\[code\]Types TypeId int Name stringProducts ProductId int TypeId int (fk) Name string Rate decimal(5, 3)BasePrices BasePriceId int TypeId int (fk) Price decimal(5,3)\[/code\]Now, I wish to display a list of products and their calculated prices within a view. Furthermore, I wish to be able to ask the user how many of the item which they wish to order e.g. by having an input text box next to each product item.The Unit price will be calculated as follows (in kind of pseudo code):\[code\](BasePrice.Price where Type = "Fruit") * Product.Rate\[/code\]My problem is that The BasePrices table connects to the Products Table via the Types Table. I am very new to ASP.NET, and and MVC and Linq, and I am not really sure how I should be modelling / querying this.In MySql, I would normally just run the following query to pull off a list of products and their current prices...\[code\]SELECT P.Name as Product, T.Name as Type, P.Rate * B.PriceFROM BasePrice as B, Products as P, Types as TWHERE T.Type = "Fruit" AND T.Type = B.Type\[/code\]The above would work in mySQL despite there not being a SPECIFIC link between the Product and BasePrice Tables.In my Products Model, should I include a BasePrices navigation property? How would I do this, if there is no direct link between the two? e.g. there is no BasePriceId within the ProductsModel for business logic related reasons.Excuse dodgy syntax, but this is kind of how I think I should be doing it within c# controller.\[code\]public ActionResult Index() {ApplicationDB db = new ApplicationDB();var products = db.Products.Include(b => b.BaseRates).Include(t => t.Types). Where(t => t.Type == "Fruit"); // This is where I get stuck...}\[/code\]Alternatively, should I be creating a new Calculator.cs file within the model which does all the math for me, then use the controller to query the calculator.cs model? any idea how I should be doing this?Any guidance would be much appreciated.