BLACK JACK

Get busy living, or get busy dying.
posts - 24, comments - 193, trackbacks - 30, articles - 3

2008年8月8日

SQL Server 2008 RTM 已经发布,并且可以从MSDN下载。

sql08rtm

说明的文字里面提到VS 2008 SP 1在8月11号后就可以下载了。注意是说August 11后就能下载(准确说是从Aug 12算起),而不是要到August 11之后的某天才能下载。不知道我理解的对不对。

另外,Danny在system.data.objects的blog上也说EF v1 is almost here.

posted @ 2008-08-08 14:14 J. Lin 阅读(256) 评论(0) 编辑

2008年3月20日

这东西真的很棒。如果你的系统里需要定义类似Community Server里那样复杂的配置文件的话,它可是帮上大忙了。

不仅可以生成配置类,还能生成schema和sample,外部的自定义类型也能方便的设定。

另外项目还是开源的,地址:

http://www.codeplex.com/csd

废话不多说了,大家自己玩吧。

image

 

Update:  刚才发现新发布的1.1版本似乎有点问题,大家可以先下1.0.2的用
Update: 1.1.1修复安装包已放出

posted @ 2008-03-20 12:15 J. Lin 阅读(2516) 评论(15) 编辑

2008年3月7日

前些天看了Jeffrey扩展LINQ to SQL:使用Lambda Expression批量删除数据。说实话解析表达式生成Where Condition的那部分代码基本没看懂(事实是代码太多实在是没耐心看)。

根据Linq to Sql原有的设计,解析Query得到DbCommand应该是SqlProvider干的事,只是现在这个SqlProvider只从IReaderProvider出(事实上MS也没设计个IUpdateProvider或者IDeleteProvider来着),所以也只对SELECT感冒。搞的咱们只能在DataContext里自力更生了。

不过既然已经有了可以生成SELECT的IReaderProvider,稍微把SELECT语句改造一下不就能得到DELETE了吗!基本思路:

        public static int DeleteAll<TEntity>(this Table<TEntity> table, Expression<Func<TEntity, bool>> predicate)
           
where TEntity : class
       
{
           
IQueryable query = table.Where(predicate);
           
DbCommand com = dc.GetCommand(query);

            //TODO:改造sql语句

            return com.ExecuteNonQuery();
         }
    }

这里直接拿直接拿where生成的query来GetCommand,得到的sql语句大致如下:

SELECT fields... FROM tableName AS TableAlias WHERE Condition

 

我们的目标是改造成:

DELETE FROM tableName WHERE Condition

 

可见关键是得到tableName,用正则是首选。不过这里还有一个缺陷就是只能用expression来做删除不能用linq query,比如我想这样:

            var query = from item in context.Items
                       
where item.Name.StartsWith("XX")
                       
select item;
            context.DeleteAll(query);

看来要把DeleteAll放到DataContext里,不过这样有风险,有可能会接受到无法转换的SELECT语句,增加判断必不可少。

最终完成如下:

    public static class DataContextEx
    {
        public static int DeleteAll(this DataContext dc, IQueryable query)
        {
            DbCommand com = dc.GetCommand(query);

            Regex reg = new Regex("^SELECT[\\s]*(?<Fields>.*)[\\s]*FROM[\\s]*(?<Table>.*)[\\s]*AS[\\s]*(?<TableAlias>.*)[\\s]*WHERE[\\s]*(?<Condition>.*)",
                                    RegexOptions.IgnoreCase);

            Match match = reg.Match(com.CommandText);

            if (!match.Success)
                throw new ArgumentException("Cannot delete this type of collection");

            string table = match.Groups["Table"].Value.Trim();
            string tableAlias = match.Groups["TableAlias"].Value.Trim();
            string condition = match.Groups["Condition"].Value.Trim().Replace(tableAlias, table);

            com.CommandText = string.Format("DELETE FROM {0} WHERE {1}", table, condition);

            if (com.Connection.State != System.Data.ConnectionState.Open)
                com.Connection.Open();

            return com.ExecuteNonQuery();
        }


        public static int DeleteAll<TEntity>(this Table<TEntity> table, Expression<Func<TEntity, bool>> predicate)
            where TEntity : class
        {
            IQueryable query = table.Where(predicate);

            return table.Context.DeleteAll(query);
        }
    }


 

注:reg表达式取自MSDN Forum

posted @ 2008-03-07 18:53 J. Lin 阅读(3712) 评论(5) 编辑

2007年8月22日

IE6不支持设置transparent为边框的颜色。

例如:
border:solid 1px transparent;

tb1

解决方法:
border:solid 1px transparent;
/*set an unused color to be index color*/
_border-color:tomato; /*For IE6-*/
/*then remove this indexed color*/
_filter:chroma(color=tomato);/*For IE6-*/

结果如下:
tb2

边框是没了,可字体怎么。。。
主意,以上现象是只有在打开系统的ClearType时才会看到的,如果把ClearType关掉就没问题了,见下:
tb3 
关于这个问题的一个演示页面:
http://icant.co.uk/sandbox/msieopacityissue/
另:
http://www.hedgerwow.com/360/bugs/fix-ie-opacity-text.html

解决方法:
border:solid 1px transparent;
background-color:#BFDBFF;
/*set an unused color to be index color*/
_border-color:tomato; /*For IE6-*/
/*then remove this indexed color*/
_filter:chroma(color=tomato);/*For IE6-*/
 

tb4 
搞了半天边框是透明了,底色又不透明了,汗!!!

posted @ 2007-08-22 18:25 J. Lin 阅读(2143) 评论(7) 编辑

2007年2月7日

在iframe或frame中使用另一个域名的ASP.NET AJAX或Toolkit页面,会得到cross-domain access denied错误。
Bleroy 和 Delay 分别post了两篇文章,详细讲述了引起问题的原因以及如何解决。如果你也遇到了这个问题可以参考。

1. How to work around the access denied cross-domain frame issue in ASP.NET Ajax 1.0
2. Safely avoiding the "access denied" dialog [How to: Work around the access denied cross-domain IFRAME issue in the AJAX Control Toolkit]

太忙,暂不翻译了。

posted @ 2007-02-07 13:22 J. Lin 阅读(5910) 评论(3) 编辑

2006年11月7日

摘要: 前两天我在《不可多得的Javascript(AJAX)开发工具 - Aptana》一文中简单介绍了Aptana。大家都很关注,同时也提了很多问题。因为Aptana相关的内容比较多,不可能在一篇里全部讲完,所以我想就问题比较多的几方面陆续写几篇小文。希望能对大家有所帮助。本人也是刚刚开始使用Aptana,有不对的地方请大家包含。阅读全文

posted @ 2006-11-07 23:17 J. Lin 阅读(25359) 评论(25) 编辑

2006年11月6日

摘要: 扩展页面基类可以实现太多功能了,本篇是我平时用到的一些功能的整理。
包括:企业库操作简化,Theme选择器,语言选择器,AJAX,ViewState存储等。阅读全文

posted @ 2006-11-06 01:44 J. Lin 阅读(3614) 评论(1) 编辑

2006年11月5日

摘要: 自从开始做Web开发起,一直都没有找到一个很让人满意的Javascript开发工具。从Editplus、Dreamweaver到FrontPage、Visual Studio,没有一样是很称手的。你是不是还在为Visual Studio中的那一点点智能提示感到兴奋不已?的确VS比其他的好那么一点点,但是相对于VS中的C#、VB等来说对javascript的支持实在是太少了。下面我要向你介绍一款非常...阅读全文

posted @ 2006-11-05 01:18 J. Lin 阅读(31482) 评论(49) 编辑

2006年10月28日

摘要: 这个是很久以前就在用的,今天突然发觉家里的机器上居然没装。一下忘了怎么弄,搞了半天才搞好。特此记录背忘。实现效果:在文件夹上右键,选择“Open as Visual Studio Website”,VS自动打开并加载此文件夹为一个Website项目步骤:1。在VS2005中选择 Toos/Macros/Macros IDE2。选中MyMacros项目,并添加一个一个module,命名为“Websi...阅读全文

posted @ 2006-10-28 01:18 J. Lin 阅读(369) 评论(1) 编辑

2006年5月11日

摘要: http://www.vsteamsystemcentral.com/cs/blogs/applied_team_system/archive/category/1005.aspxhttp://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=01fbed6b-cb29-417e-ad24-56183fb9159...阅读全文

posted @ 2006-05-11 19:19 J. Lin 阅读(281) 评论(0) 编辑