私のサイトの1つをWebFormsからMVC Coreにアップグレードしています。データベースの作成方法についてアドバイスをお願いしますか? Rabbit Bikes Productsページの背後にある.VBファイルのコード例を次に示します。彼らの製品の多くは2つ以上の価格を持っているので非常に乱雑です。ASP.NET Core MVC複数の価格を持つ製品データベース
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
ASP.NETコア1.1とEntity Frameworkのに切り替えるので、私は、各項目の価格の数を確認する方法を把握しようと、それらを適切にラベル付けされてきました。配列を使用しようとしましたが、Entity Framework Modelクラスの各変数型がSQL Serverデータ型に接続されているため、これらは動作しません。 if/elseステートメントを使って各製品に関連付けられている価格の数を数え、適切にラベルを付け直したいとは思わない。 My Productクラスは、Entity FrameworkとCSSを使用したASP.NET MVCのものと大きく異なるわけではありません。
public class Product
{
public int ID { get; set; }
public string Image { get; set; }
[Display(Name = "Product Name")]
public string Name { get; set; }
public string Description { get; set; }
public string PriceLabels { get; set; }
public decimal Prices { get; set; }
//Add a third table to hold price information?
//public int? PriceTableID { get; set; }
public int? CategoryID { get; set; }
[Display(Name = "Category Name")]
public virtual Category Category { get; set; }
}
この問題についてご理解いただきありがとうございます。
私は何か類似していると思っていました。その製品のラベルと価格を保持する価格表を作成し、2つの表を製品表への参照と、価格表の価格IDへの別の参照とをリンクします。 '\t //価格情報を保持する3番目のテーブルを追加しますか? ' ' \t // public int? PriceTableID {get;セット; } ' 複数の価格があるため、この行も追加する必要がありますか? 'public virtualカテゴリカテゴリ{get;セット; } ' – Shortstuff81000