什麼是用於存在於SQL中的LINQ和類型表的最佳設計模式。LINQ +類型表最佳實踐
我有SQL中的表限制值來鍵入值,我希望能夠在我的C#代碼中用作強類型值。
我要 'PackageStatus' 型電流的方法如下:
SQL表
PackageStatusType (int)
desc (varchar)
C#類 - 使用LINQ
public class PackageStatusType
{
static PackageStatusType()
{
var lookup = (from p in DataProvider.ShipperDB.PackageStatus
select p).ToDictionary(p => p.Desc);
Unknown = lookup["Unknown"];
LabelGenerated = lookup["Label generated"];
ReadyForCollection = lookup["Ready for pickup"];
PickedUp = lookup["Picked up"];
InTransit = lookup["In Transit"];
DeliveryAttempted = lookup["Delivery attempted"];
DeliveredByHand = lookup["By hand"];
DeliveryFailed = lookup["Delivery failed"];
Delivered = lookup["Delivered"];
Voided = lookup["Voided"];
}
public static ShipperDB.Model.PackageStatus Unknown;
public static ShipperDB.Model.PackageStatus LabelGenerated;
public static ShipperDB.Model.PackageStatus ReadyForCollection;
public static ShipperDB.Model.PackageStatus PickedUp;
public static ShipperDB.Model.PackageStatus InTransit;
public static ShipperDB.Model.PackageStatus DeliveryAttempted;
public static ShipperDB.Model.PackageStatus DeliveryFailed;
public static ShipperDB.Model.PackageStatus Delivered;
public static ShipperDB.Model.PackageStatus DeliveredByHand;
public static ShipperDB.Model.PackageStatus Voided;
}
然後我可以把PackageStatusType.Delivered
放在我的C#代碼中,它會正確地引用正確的LINQ實體。
這工作得很好,但讓我疑惑:
一)我怎麼能做出這種更有效 b)爲何沒有微軟似乎提供任何創建強類型的類型表 c)是我的數據庫設計一個好的? d)其他人都在做什麼!
謝謝!
正是我所希望的! – 2010-10-13 18:57:17