什么是用于存在于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