RSS

Property editing not available

If you open the XAML-Editor in Visual Studio 2010, select a Control and open the Property-Editor and you get the message “Property editing not available” the simplest solution is that you open the Design-View and then switch back to the XAML-Editor. Then you get back the Property-Editor.image

 
Leave a comment

Posted by on May 10, 2012 in Visual Studio 2010, WPF

 

Tags: ,

The Solution appears to be under Source Control, but its Binding Information cannot be found.

You might get following error during opening your solution in Visual Studio 2010 if you have a workspace located on a Team Foundation Server 11.

The solution appears to be under source control, but its binding information cannot be found. Because it is not possible to recover this missing information automatically, the projects whose bindings are missing will be treated as not under source control.

This is because you might have upgraded your workspace with Visual Studio 11 to a local workspace.

image

In that situation you can no longer open your solution with Visual Studio 2010. If you try this you will get the error as shown above.

Solution steps:

  1. Create one server workspace for Visual Studio 2010 and another local workspace for Visual Studio 11

    1. Open the Source Control Explorer in Visual Studio 11.
    2. Open the Drop Down Button right of the Workspace Label.image
    3. Select Workspaces.
    4. After opening the Manage Workspace window click Add.
    5. Enter a name to identify that workspace.
    6. Under Source Control Folder select the folder you want to map.
    7. Under Local Folder select the folder where you want to map to.
    8. Then click Advanced.
    9. The next step is the important one:
      1. For Visual Studio 2010 you need a workspace that has its Location on the Server.
      2. For Visual Studio 11 you may open workspaces with both types.image
  2. Change your local workspace to a server workspace.

    1. Follow Steps 1.1  to 1.8
    2. Select as Location Server.
 

Tags: , ,

Create UNIQUE Constraint and allow NULL values

If you create an unique constraint using

ALTER TABLE tbl ADD CONSTRAINT UK_tbl UNIQUE(possibleNullValueTable);

you have the problem that you can insert only one row with a NULL value.
But if you create a filtered unique index like you can see in the next statement you can insert as many NULL values as you want.
CREATE UNIQUE INDEX UIX_tbl ON tbl ( possibleNullValueColumn ) 
WHERE possibleNullValueColumn IS NOT NULL

Now you can try the follwoing scipt to prove my assumtion:
CREATE TABLE Test(
	Id int IDENTITY(1,1) NOT NULL,
	PossibleNullValueFK int NULL
	CONSTRAINT PK_Test PRIMARY KEY CLUSTERED ( Id ASC ))

CREATE UNIQUE INDEX UIX_tbl ON Test(PossibleNullValueFK) where PossibleNullValueFK IS NOT NULL

INSERT INTO Test (PossibleNullValueFK) VALUES (1)
INSERT INTO Test (PossibleNullValueFK) VALUES (2)
INSERT INTO Test (PossibleNullValueFK) VALUES (NULL)
INSERT INTO Test (PossibleNullValueFK) VALUES (3)
INSERT INTO Test (PossibleNullValueFK) VALUES (NULL)
INSERT INTO Test (PossibleNullValueFK) VALUES (NULL)
-- Executing the next statement raises a UNIQUE Violation Exception.
INSERT INTO Test (PossibleNullValueFK) VALUES (3)

 
Leave a comment

Posted by on May 9, 2012 in SQL

 

Tags:

Show a List as ReadOnly

I have often the situation when I need showing a list and I do use a ListBox I do not need that the selected item is highlighted. If I use a ListBox for displaying a list of data then this looks like:

image

But as you can see there is a highlighted item which we want to avoid. How can we avoid that? This is achieved by using an ItemsControl. Then we have solved the problem and the list looks like:

image

 
Leave a comment

Posted by on May 9, 2012 in C-Sharp, WPF

 

Tags: ,

Remove items from a collection that matches a constraint

If you want to remove some elements that are matching a constraint from a list, and you use a foreach loop to traverse the list you get the exception you will get an exception saying that you cannot change the collection during an enumeration of if you remove an item.

List list = new List() { 6, 8, 7, 8, 9,6, 3, 7,8, 4, 10, 0 };
foreach (var item in list)
{
    if (item > 5)
    {
        list.Remove(item);   //here you will get the exception
    }
}

This is because you cannot modify a collection during enumerating it. Despite you cannot remove an item, you also could not add any item. This problem could be addressed by changing the foreach-loop with a for-loop

List list = new List(){ 6, 8, 7, 8, 9,6, 3, 7,8, 4, 10, 0 };
for (int index = 0; index < list.Count; index++)
{
    var item = list[index];
    if (item > 5)
    {
        list.Remove(item);
    }
}

And the problem is solved! Or is it?

No it is not. Just watch the resulting list8,8,6,3,8,4,0 where it should be 3,4,0.

This is because you have following:

Position List content remove it
0 6,8,7,8,9,6,3,7,8,4,10,0 yes
1 8,7,8,9,6,3,7,8,4,10,0 yes
2 8,8,9,6,3,7,8,4,10,0 yes
3 8,8,6,3,6,3,7,8,4,10,0 no
4 8,8,6,3,7,8,4,10,0 yes
5 8,8,6,3,8,8,4,10,0 yes
6 8,8,6,3,4,10,0 yes
7 8,8,6,3,4,0

As you se, you skip some items. This problem can be addressed by not increasing indesif you find an item to remove or you traverse the list beginning at the end:

for (int index = list.Count -1; index >= 0; index--)
{
    var item = list[index];
    if (item > 5)
    {
        list.Remove(item);
    }
} 

Another possibility is to use the LINQ-Extension-Method RemoveAll

 list.RemoveAll(item=>item > 5); 

 
Leave a comment

Posted by on May 6, 2012 in C-Sharp, LINQ

 

Object mapping could not be found for Type with identity {X}

If you try executing TryGetObjectByKey and you get the error above, you have missed to set the MetadataWorkspace in your ObjectContext.
This is achieved by doing the following:

Assembly a = typeof(MyContext).Assembly;
//ctx is the ObjectContext
ctx.MetadataWorkspace.LoadFromAssmebly(a);

After that you will be able to execute TryGetObjectByKey or other methods without getting exceptions.

 
Leave a comment

Posted by on May 2, 2012 in C-Sharp, EF

 

Tags:

Source Control Explorer is grayed out

If your Source Control Explorer menu item is grayed out, you need to check whether you have selected any Source Control plug-in. In order to check that you need to do following steps.

  • Open the Tools menu.
  • Select the Options menu.
  • In the tree view select Source Control.
  • Under Current source control plug-in with value None select either:
    • Visual Studio Team Foundation Server
    • Or Any other source control provider that is in the list and you want to use.
 
Leave a comment

Posted by on March 16, 2012 in Visual Studio

 

Tags:

Update SQL Database Project Scripts from Database

If you create an empty SQL Database Project and if you already have an existing database with tables, stored procedures, etc. you can use following steps to create or update the SQL Database Project.

  • Open the Solution Explorer.
  • Right click on the SQL Server Project
  • Select Schema Compare

image

  • Click the Switch source and target button in the middle, to swap the DatabaseProject to the right.
  • Select left in where the source field is in the drop down menu Select Source.
  • In the window that opens insert all SQL Credentials of the database.
  • Then After inserting Click the Compare button to list all differences
  • If the Database Project is empty you will get a list of all objects of the database. But if the Database has only a few changes you get a list as the following:

image

  • As you can see, you will immediate get a overview about what has changed.
  • Now you can select the changes you want to update and click the Update button.
  • That’s all. You have successfully updated or created the Database Project. Now the Database and the Database Project has the same schema.

If you desire you can also do the reverse way and update your database with the changes made in the SQL Database Project. But I do not suggest to do that this way. You should do that by publishing the SQL Database Project to the SQL Server. Doing that you can provide a Pre- and Post-Deployment Script. In those script you  can integrate queries to migrate data during the deployment process.

 
Leave a comment

Posted by on March 16, 2012 in SQL, Visual Studio

 

Tags: ,

TFS 11 Beta: Permission Error with creating a team project

If you try to create a new team project in the Beta version of the new Team Foundation Server 11 using Visual Studio 2010 you will get following error:

TF30172: You do not have permission to create a new team project.

Even if you have set the permissions and you are eligible to create such a project you will get the error. The only solution until now is using the new version of Visual Studio 11 Beta to create a new team project with.

 

Tags: ,

Validating Binding

Writing XAML Code is very cool, but if you have a control in which you have to write several times

<TextBox Text="{Binding Path=... ValidatesOnDataErrors = true, 
                ValidatesOnException = true, 
                UpdateSourceTrigger = PropertyChanged}" />

might be very stressul and unclear in case of searching errors. Therefore I have created following class, called ValidatingBinding, that inherits from Binding and sets at creation time the properties ValidatesOnDataError and ValidatesOnExceptions to true
public class ValidatingBinding : Binding
{
    public ValidatingBinding()
    {
        ValidatesOnDataErrors = true;
        ValidatesOnExceptions = true;
        //and if needed (be careful, might be a performance issue)
        //UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
    }
}

Doing that you will be able to write following in XAML and omit to set the properties ValidatesOnDataError and ValidatesOnExceptions to true.
<TextBox Text="{namespace:ValidatingBinding Path=... }"/>

As you can see, this is much shorther than the previous example. Reviewing such XAML Code is more clear if you do not rewrite such duplicate property setting.

 
Leave a comment

Posted by on February 23, 2012 in WPF

 

Tags: ,

 
Follow

Get every new post delivered to your Inbox.