C# 具有多个价格的ASP.NET核心MVC产品数据库
我正在将我的一个网站从WebForms升级到MVC Core。你能给我一些关于如何建立他们数据库的建议吗?下面是页面后面的.VB文件中的一些示例代码。这是非常混乱的,因为他们的许多产品有两个或两个以上的价格C# 具有多个价格的ASP.NET核心MVC产品数据库,c#,sql-server,asp.net-mvc,entity-framework,asp.net-core,C#,Sql Server,Asp.net Mvc,Entity Framework,Asp.net Core,我正在将我的一个网站从WebForms升级到MVC Core。你能给我一些关于如何建立他们数据库的建议吗?下面是页面后面的.VB文件中的一些示例代码。这是非常混乱的,因为他们的许多产品有两个或两个以上的价格 For Each prod As Product In myProducts 'Beginning Layout temp &= "<article class=""dbItem""><figure class=""left dbIm
For Each prod As Product In myProducts
'Beginning Layout
temp &= "<article class=""dbItem""><figure class=""left dbImage"">"
temp &= "<img src=""" & prod.ImagePath & """ alt=""" & prod.Name & """ title=""" & prod.Name & """ style=""width: 100%;"" class=""pull-left img-rounded""></figure>"
temp &= "<h2>" & prod.Name & "</h2>"
temp &= "<div class="" scroller""><p>" & prod.Description & "</p></div>"
If Not prod.Description.Contains("shuttle") And Not prod.Name = "Trail Pass" Then
temp &= "<h3 style=""text-transform: uppercase;"">Call to reserve yours today!</h3>"
Else
temp &= "<h3 style=""text-transform: uppercase;"">Call to purchase one today!</h3>"
End If
temp &= "<br /><div style=""text-align: center;"">"
If prod.Description.Contains("shuttle") Or prod.Description.Contains("frequent rider") Then
temp &= "<span class=""oSnap"">One Person:</span> " & prod.TwoHrPrice.ToString("c") & "<br/>"
temp &= "<span class=""oSnap"">2 or More <abbr title=""people"">ppl.</abbr>:</span> " & prod.FourHrPrice.ToString("c") & "</p>"
End If
If prod.TwoHrPrice = 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<p>Free with purchase!</p>"
End If
If prod.FourHrPrice <> 0 And Not prod.Description.Contains("shuttle") And Not prod.Description.Contains("frequent rider") Then
temp &= "<p><span class=""oSnap"">Half Day Price:</span> " & prod.FourHrPrice.ToString("c") & "<br/>"
End If
If prod.OneDayPrice <> 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<span class=""oSnap"">One Day Price:</span> " & prod.OneDayPrice.ToString("c") & "<br/>"
End If
If prod.TwoDayPrice <> 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<span class=""oSnap"">Two Day Price:</span> " & prod.TwoDayPrice.ToString("c") & "<br/>"
End If
If prod.WeekPrice <> 0 And Not prod.Description.Contains("shuttle") Then
temp &= "<span class=""oSnap"">Week Price:</span> " & prod.WeekPrice.ToString("c") & "</p>"
End If
'End Layout
temp &= "</div></article>"
Next
如果您对这个问题有任何见解,我将不胜感激。您的问题到底是什么?一般性建议在这里是离题的。你应该问一个特定的问题以得到特定的答案。如果您的问题是如何计算价格,只需执行查询并使用count方法linq。例如,假设您的数据库上下文称为db,产品表为products
var count = db.Products.Where(x => x.ProductId == yourproductid).Count();
在这个场景中,每个产品/价格组合都有多个条目。另一种选择是创建一个一对多的产品到价格,然后分别查询价格
这是非常基本的Linq功能,而且您似乎非常缺乏经验,所以我建议您阅读一些有关实体框架的教程。EntityFramework核心在细节上有点不同,但就查询而言,其工作原理与传统实体框架基本相同。我也在考虑类似的问题;创建一个包含该产品的标签和价格的价格表,然后使用对产品表的引用和对价格表中价格ID的另一个引用链接这两个表`//添加第三个表来保存价格信息?``//公共int?PriceTableID{get;set;}`既然有多个价格,我是否也需要添加这一行?公共虚拟类别{get;set;}
var count = db.Products.Where(x => x.ProductId == yourproductid).Count();