June 30, 2011

Cannot apply indexing with [] to an expression of type System.Collections.Generic.IEnumerable

Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.IEnumerable<ANY_TYPE>

If used of IEnumerable SampleArray then you can access to elements like:
- SampleArray[index] WRONG
- SampleArray.ElementAt(index) RIGHT
Because the IEnumerable interface dose not support of [] for indexing :-))

June 15, 2011

Server-generated keys and server-generated values are not supported by SQL Server Compact

{"Server-generated keys and server-generated values are not supported by SQL Server Compact."}
{"An error occurred while updating the entries. See the inner exception for details."}

The current version of Entity Framework does not support identity keys using SQL Compact ;-(

1- Add the Guid.NewGuid() after new row like below here (for uniqueidentifier ID)

BindingListCollectionView CurrentView = categoriesViewSource.View as BindingListCollectionView;
Table tb1 = CurrentView.AddNew() as Table1;
tb1.ID = Guid.NewGuid();

2- Another solution can be find the last and greatest ID and make a new one with ++ to that like here (for int ID)

3- Another solution can be used of  DateTime.UtcNow.Ticks (for bigint ID)

PS: There's a little problem with True value for Identity property in SQL CE Table and must be set to False.

June 12, 2011

Make invisible layer in Flash CS5

Hide layer (with click on eye icon) for invisible in design time and then right-click on layer and checked the Guide item for invisible in run-time.

June 06, 2011

Primary side of the relationship error on Entity Framework

The relationship 'RELATIONSHIP NAME' has columns that are not part of the key of the table on the primary side of the relationship. The relationship was excluded.

Attention to the RELATIONSHIP NAME in your database. The Relationship Name must have a unique name and this error comes from a duplicate relationship name in database. Entity Framework (EF 4.0) generator have problem with duplicate relationship names from databases.

June 01, 2011

WPF SelectedValue for TreeView

- How to programmatically select an Item in a WPF TreeView
- How to programmatically selecting an Item in a WPF TreeView
- How to SelectedItem in a WPF TreeView
- How to set SelectedItem or SelectedValue in C#/WPF TreeView
- WPF TreeView SelectedItem should have set accessor …
- How to programmatically change the SelectedItem in a WPF TreeView

The Solution is simple and quick with just a little method
TreeViewItem matchItam = SelectTreeViewItem(this.treeView1.Items, "sample value");

The code is here
private TreeViewItem SelectTreeViewItem(ItemCollection Collection, String Value)
    if (Collection == null) return null;
    foreach(TreeViewItem Item in Collection)
        /// Find in current
        if (Item.Header.Equals(Value))
            Item.IsSelected = true;
            return Item;

        /// Find in Childs
        if (Item.Items != null)
            TreeViewItem childItem = this.SelectTreeViewItem(Item.Items, Value);
            if (childItem != null)
                Item.IsExpanded = true;
                return childItem;
    return null;

C# HTML Minification

- Is there any code which input the html source of a page and it will minify the code?
- A solution for Text Compress without used of GZip for...
- Minifies given HTML or XML source by removing extra whitespaces, comments and other unneeded Characters without breaking the content structure
- Minify HTML (or XHTML), and any CSS or JS included in your markup
- Compressing and Minifying HTML Markups

I hope this helps.
/// Solution A
html = Regex.Replace(html, @"\n|\t", " ");
html = Regex.Replace(html, @">\s+<", "><").Trim();
html = Regex.Replace(html, @"\s{2,}", " ");

/// Solution B
html = Regex.Replace(html, @"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}", "");
html = Regex.Replace(html, @"[ \f\r\t\v]?([\n\xFE\xFF/{}[\];,<>*%&|^!~?:=])[\f\r\t\v]?", "$1");
html = html.Replace(";\n", ";");

/// Solution C
html = Regex.Replace(html, @"[a-zA-Z]+#", "#");
html = Regex.Replace(html, @"[\n\r]+\s*", string.Empty);
html = Regex.Replace(html, @"\s+", " ");
html = Regex.Replace(html, @"\s?([:,;{}])\s?", "$1");
html = html.Replace(";}", "}");
html = Regex.Replace(html, @"([\s:]0)(px|pt|%|em)", "$1");

/// Remove comments
html = Regex.Replace(html, @"/\*[\d\D]*?\*/", string.Empty);

- Is there a better approach to minify html generated from aspx page
- Efficient stylesheet minification in C# 
- Follow up to Additional CSS minifying regex patterns
- Improve ASP.NET Performance - CSSmin