DataRow.SetParentRow Method

I’ve noticed an existence of DataRow.SetParentRow Method.
MSDN documentation is quite brief: Sets the parent row of a DataRow with specified new parent DataRow.
 
It wasn’t clear does the functions fills foreign key values in the child row from the parent one.
Thanks to Reflector, I confirmed, that it does SetKeyValues .
 
Please note that from performance point of view it is important to call SetParentRow first and add the childRow to the child table later..
Advertisements

XmlChoiceCollection class to access XSD generated properties for choice XML elements

When I used XML Schema Definition Tool (Xsd.exe) ,  it creates proxy class with extra ItemsChoiceType array and enum for xsd:choice  elements. 

MSDN XmlChoiceIdentifierAttribute Class article shows example of XSD, generated proxy class and how to fill  pairs of arrays:

// Populate an object array with three items, one

      // of each enumeration type. Set the array to the

      // ManyChoices field.

      object[] strChoices = new object[]{“Food”,  5, 98.6};

      myChoices.ManyChoices=strChoices;



      // For each item in the ManyChoices array, add an

      // enumeration value.

      MoreChoices[] itmChoices = new MoreChoices[]

      {MoreChoices.Item,

      MoreChoices.Amount,

      MoreChoices.Temp};

      myChoices.ChoiceArray=itmChoices;



I found that support two arrays for items itself and for EmlementNames is error prone and created helper generic XmlChoiceCollection class, that allows to add items and types inone Add method.

 

#region  Namespace Imports

using System;

using System.Collections.Generic;

using System.Text;

#endregion  //Namespace Imports

 

    /// <summary>

    /// see http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlchoiceidentifierattribute(printer).aspx

    /// </summary>

    public class XmlChoiceCollection<TItem,TItemsChoiceEnum>

    {

        public List<TItem> _items;

        public List<TItemsChoiceEnum> _elementNames;

        public XmlChoiceCollection()

        {

            _items=new List<TItem>() ;

            _elementNames=new List<TItemsChoiceEnum>();

        }

        public void Add(TItem item, TItemsChoiceEnum elementName)

        {

            _items.Add(item);

            _elementNames.Add(elementName);

        }

        public TItem[] ItemsToArray()

        {

           return   _items.ToArray();

        }

        public TItemsChoiceEnum[] ElementNamesToArray()

        {

            return _elementNames.ToArray();

        }

 

    }

Example of use:
XmlChoiceCollection<MyElement, ItemsChoiceType> choiceCollection = new XmlChoiceCollection<MyElement, ItemsChoiceType>();
for (int i = 0; i < Count; i++)
{
   choiceCollection .Add(new MyElement(), ItemsChoiceType.type1);
}

request.Items = choiceCollection.ItemsToArray();
request.ItemsElementName = choiceCollection.ElementNamesToArray();

 

Shortkey Alt-B,U is ambiguous in Visual Studio 2008 team edition

 

In Visual Studio I like to use shortkey Alt-B,U to start build of the current project.
However in VS 2008 team edition it doesn’t start the build, but just opens menu and waits for extra “Enter” click.
The reason is that on the Build menu,there is extra “Queue new build” menu item with the same u shortcut, which conflicts with “Build Project”  menu item.
The issue reported to MS Connect and they told, that it is fixed in a future release.
 
Is it possible to change alt shortkeys for standard menu items?



I know that I can assign new shortkeys using Customize, but my hands need  to remember this new key, and my preference is to hide-disable  shortkey for “Queue new build” , which I am not using anyway.

QuickCode.Net 2008 new TAB shortcut key

QuickCode.Net  has a new free 2008 version.

UPDATE: in a new release 3.0.6. it’s possible to assign any shortcut key. In VS 2008  Customise keyboard  I’ve selected command QuickCode2008.AddIn.ReplaceQuickCode  and assigned a shortcut key Alt-Q.

It uses <TAB> instead of previously assigned Alt-Q hotkey.

<TAB> is consistent with standard VS snippets.

 If you press the TAB key after your QuickCode, e.g.

tc<TAB>

the QuickCode will expand.

If the same pattern exists in snippets and QuickCode, the VS snippet goes first. QuickCode deliberately does NOT expand QuickCodes while Intellisense is active.

After some use of new QuickCode.Net 2008  I understood that I prefer old Alt-Q , not new Tab

 

 The reasons for this are the following:
1. when typing, because of active Intellisense list it usually requires to do <ESC> to clear list , and only then <Tab> , instead of simple <Tab>
2. To clicking <Tab>, you need to be at the end of line.
E.g. if you typed your macro and want to fix typo in the middle of the line , you neet to go to the end of the line next.
Alt-Q didn’t have this requirement.
3. Parameter with spaces doesn’t work with TAB.
E.g. I have a macro
#r Region description with spaces
that converts into
#region  “Region description with spaces”
#endregion  //”Region description with spaces”
It worked with Alt-Q, but when using TAB, spaces within parameter are not supported.
UPDATE: Markus from (MOBZystems) adviced me to use Optional arguments:
To support spaces In the following QuickCode macro in the pattern use :  not
#r %%desc%%
But
#r %{desc}%.
 
<?xml version=”1.0″ ?>
<quickcodes version=”3.0″>
  <quickcode description=”region” pattern=”#r %{desc}%” priority=”0″>
    <expansion language=”Basic”><![CDATA[#region “%%desc%%”
#End Region ‘ %%desc%%]]></expansion>
    <expansion language=”CSharp”><![CDATA[#region “%%desc%%”
#endregion // %%desc%%]]></expansion>
  </quickcode>
</quickcodes>
  
And everything works as expected!
 Tip: You can copy the XML above to the clipboard and paste it into the QuickCode list to copy this QuickCode to your own collection.

Ideally it would be good if QuickCode  will support both keys. 

Related link(s):

My older post: QuickCode commands file location

 

“Login failed for user” may mean “database name is invalid”

One of my colleagues tried to work with a new database from DevServer and got an error “Login failed for user”.
We checked everything related to security and permissions, but it didn’t help.
After a while we recognize that there was spelling mistake in the name of the database in connection string.
In this case  Login failed for user” error actually meant  “database name is invalid”
 
Why it wasn’t shown as a reason in plain English?
 
Other possible reason for the errors are described in multiple articles, including following:

Generate C# class from XSD file.

I have an existing C# file, generated a long time ago from XSD definition.
The XSD files were changed, and proxy class should be regenerated.
I’ve tried to use XML Schema Definition Tool (Xsd.exe) to generate C# class, but it  returned the error: “The datatype is missing”.
I’ve actually have two XSD files -outer and imported
Thanks to the post: XSD.exe is kicking my butt, man…redux , it pointed me to specify all necessary files on the commandline.
Note that name of generated file is combined from the files listed
  
I’ve created the batch file to be able to rerun it  
CallXSD.BAT
@call “C:Program FilesMicrosoft Visual Studio 8VCvcvarsall.bat” x86
xsd.exe outer.xsd imported.xsd /classes /l:cs /n:MyNamespace

rem rename  outer_imported.cs as outer.cs 
pause

By some reason the generated file created in some non-default encoding, which inserts 3 characters

 in the beginning.It is a minor annoyance, but when I delete them, VS shows me a warning, that wrong encoding could prevent keeping history.
 
The next issue was that the new XSD(.Net Framework 2.0 and 3.5) generates C# classes differently with what 1.0/1.1 XSD.exe did.
In a few places 1.1 version generated custom collection of objects, but new XSD.EXE generates array of objects, so I have to change the calls to generated classes.

Another problem with XSD generated classes is that it disables  step into debugging even on methods that you  extended in partial classes by specifying DebuggerStepThroughAttribute for classes. Workarounds are described in XSD.exe and DebuggerStepThrough post.  Issue reported to MS Feedback.

I should try An XSD to .NET language code class generator that adds real punch to Microsoft’s XSD Tool.
or Sample Code Generator 1.4.2.1

Another issue was that authors of XSD file added   xsd:choice  elements and it creates extra ItemsChoiceType array and enum.I described how I addressed it in my post XmlChoiceCollection class to access XSD generated properties for choice XML elements

 

That’s pity, that minor changes in XSD file causes different class properties to be generated and essential code  changes to access the new properties.

Visual studio 2008 “Build action” properties: Shadow and CodeAnalysisDictionary

I’ve noticed that in Visual Studio 2008  files have additional “Build action” properties: Shadow and CodeAnalysisDictionary.
I’ve tried to find their meaning on Google but without success.
Does anyone know,what they suppose to do?