What is the best design pattern for LINQ and type tables existing in SQL.
I have tables in SQL that restrict values for inputting values, and I want to be able to use this in my C # code as strongly typed values.
My current approach for type PackageStatus is as follows:
SQL table
PackageStatusType (int)
desc (varchar)
C # Class - Using 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;
}
Then I can put PackageStatusType.DeliveredC # in my code and it will correctly refer to the right LINQ object.
This works great, but makes me wonder:
a) how can I make it more efficient b) why does Microsoft seem to create nothing to create tables of strongly typed types c) is my database design even good? d) what everyone else is doing!
thank!