posts - 83, comments - 184, trackbacks - 0, articles - 0
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

2010年2月6日

Unity三篇好文

Unity(1)简介及简单使用
http://www.xiaozhou.net/dotnetdevelopment/unity-study-notes-1-unity-introduction-and-easy-to-use-2009-04-23.htm

Unity(2)配置文件的使用
http://www.xiaozhou.net/dotnetdevelopment/unity-study-notes-2-the-configuration-file-to-use-2009-04-25.htm

Unity(3)生命周期管理
http://www.xiaozhou.net/dotnetdevelopment/unity-study-notes-3-life-cycle-management-2009-04-28.htm

posted @ 2010-02-06 16:46 a-peng 阅读(51) 评论(0) 编辑

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx


Localize Eval data

Eval只有这两种重载,没有涉及到本地化。
protected internal object Eval(string expression);
protected internal string Eval(string expression, string format);

只能强转喽
((DateTime)Eval("CreatedDate")).ToString("MMM dd yyyy", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))

posted @ 2010-02-06 16:45 a-peng 阅读(35) 评论(0) 编辑


博客左边的存档相信大家都很常见到吧。
我写了句sql语句,希望取出年份月份记录数。

select 
    
Year(CreatedDate) as Year,
    
Month(CreatedDate) as Month,
    
Count(PostId) as Count
from
    Post
group by
    
Year(CreatedDate),
    
Month(CreatedDate)
order by
    
Year descMonth desc


然后我希望在Entity Framework里实现,我用Entity SQL实现了下。

select 
    
Year,
    
Month,
    
Count(it.PostId) as Count
from
    Entities.Post 
as it
group by
    
Year(it.CreatedDate) as Year,
    
Month(it.CreatedDate) as Month
order by
    
Year descMonth desc


生成SQL语句

SELECT 
[Project1].[C4] AS [C1]
[Project1].[C1] AS [C2]
[Project1].[C2] AS [C3]
[Project1].[C3] AS [C4]
FROM ( SELECT 
    
[GroupBy1].[K1] AS [C1]
    
[GroupBy1].[K2] AS [C2]
    
[GroupBy1].[A1] AS [C3]
    
1 AS [C4]
    
FROM ( SELECT 
        
[Extent1].[K1] AS [K1]
        
[Extent1].[K2] AS [K2]
        
COUNT([Extent1].[A1]AS [A1]
        
FROM ( SELECT 
            
DATEPART (year[Extent1].[CreatedDate]AS [K1]
            
DATEPART (month[Extent1].[CreatedDate]AS [K2]
            
[Extent1].[PostId] AS [A1]
            
FROM [dbo].[aurora_Blogs_Post] AS [Extent1]
        )  
AS [Extent1]
        
GROUP BY [K1][K2]
    )  
AS [GroupBy1]
)  
AS [Project1]
ORDER BY [Project1].[C1] DESC[Project1].[C2] DESC


如果按上面的思路用linq表达式发现要group by两次,貌似很复杂。
换个算法。

代码
from p in posts
let m 
= new ArchiveDateTime { Year = p.CreatedDate.Year, Month = p.CreatedDate.Month }
group p by m into months
orderby months.Key descending
select 
new ArchiveData { Year = months.Key.Year, Month = months.Key.Month, PostCount = months.Count() };


Entity Framework不支持带参构造函数。所以你不能使用用let m = new DateTime(p.CreatedDate.Year, p.CreatedDate.Month, 1)

所以只能自己新建一个ArchiveDateTime。


posted @ 2010-02-06 16:44 a-peng 阅读(322) 评论(0) 编辑

Application Start
应用程序启动后,会获取一个应用实例ApplicationInstance

通过HttpApplicationFactory.GetNormalApplicationInstance方法获取,在该方法中会调用InitModules初始化所有Modules,然后会调用一个Init方法。
我们可以覆盖这个Init方法来初始化一些数据。等级和InitModule中的Init一样。

posted @ 2010-02-06 16:43 a-peng 阅读(25) 评论(0) 编辑

无意间发现一个问题。
1、输入: http://demo/admin
2、被重定向到: http://demo/user/login
   正常

3、登录完成回到: http://demo/admin
4、退出完成回到: http://demo
   正常

5、输入: http://demo/admin
    既然正常显示。。。不会被重定向到http://demo/user/login

我在AdminBasePage里的代码如下:

 protected override void OnInit(EventArgs e)
{            
  if (!this.IsAuthenticated)
  {
    this.RedirectToLoginPage();
  }
  else
  {
    base.OnInit(e);
  }
}

加个断点,发现在第5个步骤时根本没有进入OnInit。。。原来被IE浏览器给缓存了,在Firefox下一切正常。

呼,只能加个清缓存的。

Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();

 

posted @ 2010-02-06 16:42 a-peng 阅读(46) 评论(0) 编辑

编译器错误消息: CS0012: 类型“System.Data.Objects.DataClasses.EntityObject”在未被引用的程序集中定义。
必须添加对程序集 “System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089” 的引用。

之前无意间出现了这个错误
在Web.config中添加<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
如下所示:

<assemblies>
  <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  <
add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  <add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</
assemblies>


可以了。

posted @ 2010-02-06 16:40 a-peng 阅读(1441) 评论(0) 编辑

IFrame需要如何自适应高度呢?
要是我们能够知道IFrame所加载页面的高度,然后设置IFrame的高度为所加载页面的高度,那么就可以达到自适应高度了。

那要怎么知道IFrame所加载页面的高度?

var clientHeight = $("#mainFrame").contents().find("body").height();

使用jQuery去查找IFrame中的body的高度,那么clientHeight就是我们想要的了。

但是我们要在什么时候去查找IFrame中的body呢?当然必须在IFrame加载完成的时候,要是IFrame还未加载完成,那我们如何取出它的body.

$("#mainFrame").load(function() {
    
var clientHeight = $("#mainFrame").contents().find("body").height();
    $(
this).height(clientHeight);
});


这个世界是不是美好了很多?

btw: 2009-12-16
今天修改了IFrame里的结构为
<div id="main"></div> float: left;
<div id="right-sidebar"></div> float: left;
$("#mainFrame").contents().find("body").height(); 取出的值为0

这是为什么呢?因为使用了float,则脱离了文档结构,你可以通过Firebug移过去,可以看到body没有选中任何区域。
那我们该怎么办呢?
只有main和right-sidebar两部分,取高的那部分不就可以了。

var mainHeight = $("#mainFrame").contents().find("#main").height();
var rightHeight = $("#mainFrame").contents().find("#right-sidebar").height();
var clientHeight = Math.max(mainHeight, rightHeight);

posted @ 2010-02-06 16:39 a-peng 阅读(203) 评论(0) 编辑

如果你确定需要这么做的话,那在您的页面加上如下meta标签:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

posted @ 2010-02-06 16:37 a-peng 阅读(186) 评论(0) 编辑

情节:安装了PowerDesigner后,打开一个WebSite,打开一个Default.aspx页面,无颜色高亮,智能提示自然无跟着消失。
环境:Visual Studio 2008 英文版
惨状如下:


打开Tools->Options->HTML Designer 出现加载此属性页时出错,悲惨。



无意间觉得奇怪,怎么今天Visual Studio突然很多地方出现中文,有点不适应。
应该是安装了PowerDesigner的原故,它默认往Visual Studio上安装了一些插件,很明显,上面的一些菜单是我默认之前没有的,如Repository菜单。

解决方法:在上面的区域设置里重新设置成英文。然后运行命令行输入:devenv /resetskippkgs
好了,一切恢复正常。


posted @ 2010-02-06 16:33 a-peng 阅读(129) 评论(0) 编辑

修改SQLServer2008数据表,保存时提示如下警告信息:

The Save (Not Permitted) dialog box warns you that saving changes is not permitted because the changes you have made require the listed tables
to be dropped and re-created.

通常都是由于所修改的表被其它表所关联,所以会提示上面的警告信息。
通常我们会想默许这种操作,可以设置:Tools -> Options -> Designers -> Table and Database Designers -> clear the Prevent saving changes that require the table to be re-created check box.

详细内容可以参数链接如下:http://msdn.microsoft.com/en-us/library/bb895146.aspx

posted @ 2010-02-06 16:30 a-peng 阅读(38) 评论(0) 编辑