Map string column in Entity Framework to Enum

Probably a nicer version. OrderStateIdentifier field is used for both JSON serialization and database field, while OrderState is only used in the code for convenience. public string OrderStateIdentifier { get { return OrderState.ToString(); } set { OrderState = value.ToEnum<OrderState>(); } } [NotMapped] [JsonIgnore] public OrderState OrderState { get; set; } public static class EnumHelper { … Read more

BackgroundWorker RunWorkerCompleted Event

If the BackgroundWorker was created from the UI thread, then the RunWorkerCompleted event will also be raised on the UI thread. If it was created from a background thread, the event will be raised on an undefined background thread (not necessarily the same thread, unless you’re using a custom SynchronizationContext). Interestingly, this doesn’t seem to … Read more

Why does closing a console that was started with AllocConsole cause my whole application to exit? Can I change this behavior?

Ah, yes, this is one of the caveats of using the Windows console subsystem. When the user closes the console window (regardless of how the console was allocated), all of the processes that are attached to the console are terminated. That behavior makes obvious sense for console applications (i.e., those that specifically target the console … Read more

How to pass a variable to the SelectCommand of a SqlDataSource?

Try this instead, remove the SelectCommand property and SelectParameters: <asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:itematConnectionString %>”> Then in the code behind do this: SqlDataSource1.SelectParameters.Add(“userId”, userId.ToString()); SqlDataSource1.SelectCommand = “SELECT items.name, items.id FROM items INNER JOIN users_items ON items.id = users_items.id WHERE (users_items.user_id = @userId) ORDER BY users_items.date DESC” While this worked for me, the following code also … Read more

How to use Except method in list in c#

The Except method returns IEnumerable, you need to convert the result to list: list1 = list1.Except(list2).ToList(); Here’s a complete example: List<String> origItems = new List<String>(); origItems.Add(“abc”); origItems.Add(“def”); origItems.Add(“ghi”); List<String> newItems = new List<String>(); newItems.Add(“abc”); newItems.Add(“def”); newItems.Add(“super”); newItems.Add(“extra”); List<String> itemsOnlyInNew = newItems.Except(origItems).ToList(); foreach (String s in itemsOnlyInNew){ Console.WriteLine(s); } Since the only items which don’t exist … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)