Stop auto closing after ipconfig command
Some minor things can be annoying if you do not know the trick to do it in an easy way. One of them is getting the system IP address using ipconfig, or executing other Windows commands directly from the Start -> Run. The problem is that the command prompt window will close automatically after execution of the command. So to avoid closing the windows automatically you have two options:
- Go to Start -> Run
- Type cmd and hit enter.
- Type the command (e.g ipconfig) in the opened window.
alternatively you can
- Go to Start -> Run
- Type cmd /K command and hit enter. (e.g cmd /k ipconfig)
CMD /K will stop the command window from closing after the command.
Microsoft Prism
I just learned about Prism as a way for developing composite applications using WPF.
Prism as a guideline:
This guidance will help you design and build flexible client applications using loosely coupled, independently evolvable pieces that work together and are integrated into the overall application. This type of application is known as a composite application.
Ref: http://msdn.microsoft.com/en-us/library/dd458941.aspx
To answer the question why using Prism, refer to http://msdn.microsoft.com/en-us/library/dd490815.aspx
Composite applications provide many benefits, including the following:
- They allow modules to be individually developed, tested, and deployed by different individuals or sub-teams…
- They provide a common shell composed of UI components contributed from various modules that interact in a loosely coupled way…
- They promote re-use and a clean separation of concerns between the application’s horizontal capabilities…
- They help maintain a separation of roles by allowing different individuals or sub-teams to focus on a specific task or piece of functionality according to their focus or expertise…
Other resources:
- Prism on CodePlex: http://www.codeplex.com/CompositeWPF
- Prism for Silverlight – An Intro to Composite Applications:
http://development-guides.silverbaylabs.org/Video/Silverlight-Prism
Entity Framework assications (Independent vs FK)
Entity Framework association is a different concept to FKs in the database schema. Supporting or not supporting the Schema FKs has been a topic for debate in the community until now. Faisal Mohamood (Program Manager of Entity Framework) believes in the following prons and cons of using FKs in a model (Ref 1):
Benefits of Foreign Keys
- Keeps it simple (for the simple cases) and allows you to deal with relationship like you deal with them in the database
- Technically, you can update relationships without having both ends loaded/materialized. This is however in reality not always interesting since you will likely load both ends but this feature is definitely useful.
Disadvantages of Foreign Keys in the Model
- It is a part of the impedance mismatch problem.
- It doesn’t allow the concepts that you would expect from relationships in objects (easily getting from one end to the other) for instance.
- Having foreign keys as well as object references for relationship navigation presents the problem of two different artifacts representing relationships – this introduces complexity and now you have to make sure that you keep these two in sync.
I think the biggest disadvantage of FKs (stated in number 2) is the conflict with the object model pattern.
However, it seems that Microsoft decided that both sides of this discussion have their valid points. So in Entity Framework .Net 4, Fks are supported and it is up to the software architects to make their decision to just use independent associations (.Net 3.5 SP1) or add the FKs to the model.
The following code snippets form ADO.Net blog illustrate the implication of using Fks as part of the model (Ref 2). In our model there are two entities Product and Category, with the association one to many where each Product belongs to one Category.
First: Using the independent association between Product and Category.
public void Create_new_Product_in_existing_Category_by_reference()
{
using (var context = new Context())
{
//Create a new product and relate to an existing category
Product p = new Product
{
ID = 1,
Name = "Bovril",
Category = context.Categories
.Single(c => c.Name == "Food")
};
// Note: no need to add the product, because relating
// to an existing category does that automatically.
// Also notice the use of the Single() query operator
// this is new to EF in .NET 4.0 too.
context.SaveChanges();
}
}
Second: Using the Foreign Key.
using (var context = new Context())
{
//Create a product and a relationship to a known category by ID
Product p = new Product
{
ID = 1,
Name = "Bovril",
CategoryID = 13
};
//Add the product (and create the relationship by FK value)
context.Products.AddObject(p);
context.SaveChanges();
}
Further Reading:
- [MSDN] Defining and Managing Relationships (Entity Framework)
- Inheritance and Associations with Entity Framework Part 3
References:
Make the ASP:Login control centre
Following my previous post you cannot use “p” or “div” tags to align a ASP:Login control to the center of the page. So to get this done, you need to set the margin property of the control to “auto”.
<body>
<form id="form1" runat="server">
<div>
<asp :login runat="server" Style="margin:auto"></asp></div>
</form>
</body>
Align a table in the middle of an HTML | XHTML page
In the past it was common to align a table in the middle of a HTML page using the following code:
<div align="center">
<table>
<tr>
<td>
Test String</td>
</tr>
</table>
</div>
However, this is no longer working as in the new XHTML standards “align” is not a valid attribute of
<table style="margin: auto;">
<tr>
<td>
Test String
</td>
</tr>
</table>