原有项目升级到NBear 3.7.0 beta build 2

下载地址: 发布 NBearV3.7 beta build 2 公开测试版

我写的项目中, 进行了以下更改..
1. 更新EntityDesignToEntityConfig.xml文件, 将EntityConfigPath注释掉, 并将 EntityConfig.xml 删除, 然后在Web.config中去掉entityConfig
<? xml version="1.0" encoding="utf-8"  ?>
< EntityDesignToEntityConfiguration  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd ="http://www.w3.org/2001/XMLSchema" >
dot.gif
<!-- <EntityConfigPath>..\website\EntityConfig.xml</EntityConfigPath>
-->
dot.gif
</ EntityDesignToEntityConfiguration >

None.gif <? xml version="1.0" ?>
None.gif
< configuration >
None.gifdot.gif
None.gif    
<!-- <configSections>
None.gif        <section name="entityConfig" type="NBear.Common.EntityConfigurationSection, NBear.Common"/>
None.gif    </configSections>
None.gif    <entityConfig>
None.gif        <includes>
None.gif            <add key="Sample Entity Config" value="~/EntityConfig.xml"/>
None.gif        </includes>
None.gif    </entityConfig>
-->
None.gifdot.gif
None.gif
</ configuration >
None.gif

原因: release_note.txt
4) Release denpendency from EntityConfig.xml files.
EntityDesignToEntity.exe tool of this version embeds meta-data configurations of entities to the gerated entities code,
which means external EntityConfig.xml files are not MUST specify now.
But if you specify external EntityConfig.xml files in Web.config/App.config, configurations in external EntityConfig.xml files will
overwrite the embedded configurations.

2. 查询方式的改变
原来的方式:
None.gif public  Comment[] GetComments( int  contentID,  int  pageSize,  int  pageNo, OrderByClip orderBy)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            WhereClip where 
= WhereClip.All;
InBlock.gif            
if(contentID >0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                where 
= Comment._.ContentID == contentID;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return gateway.GetPageSelector<Comment>(where, orderBy, pageSize).FindPage(pageNo);
ExpandedBlockEnd.gif        }

现在改成用Gateway.From()方式
  public  Comment[] GetComments( int  contentID,  int  pageSize,  int  pageNo, OrderByClip orderBy)
        {
            pageNo
-- ;
            
if (contentID  > 0 )
            {
                
return  gateway.From < Comment > ().Where(Comment._.ContentID  ==  contentID).OrderBy(orderBy).ToArray < Comment > (pageSize, pageSize  *  pageNo);
            }
            
return  gateway.From < Comment > ().OrderBy(orderBy).ToArray < Comment > (pageSize, pageSize  *  pageNo);
        }

From()方法非常类似SQL语法的行为....ToArray()中, 第一个参数为分页大小,等效与Top N, 第二个参数是忽略掉前N条记录...
当PrimaryKey是Int型, 并且是按PrimaryKey排序时, 分页采用PrimaryKey > MAX(PrimaryKey)方式(降序则为PrimaryKey < Min(PrimaryKey)), 用上面的GetComments()方法, 生成的SQL语句如下:
--  ics.GetComments(1, 10, 1);
Text      SELECT   TOP   10   [ Comment ] . [ ID ] , [ Comment ] . [ ContentID ] , [ Comment ] . [ User_ID ] , [ Comment ] . [ UserName ] , [ Comment ] . [ UserPageUrl ] , [ Comment ] . [ Title ] , [ Comment ] . [ Body ] , [ Comment ] . [ IP ] , [ Comment ] . [ ModifiedDate ]   FROM   [ Comment ]   WHERE   [ Comment ] . [ ContentID ]   =   @p6xbcgsrdnkc0xk   ORDER   BY   [ Comment ] . [ ID ]     
Parameters:
@p6xbcgsrdnkc0xk [ Int32 ]   =   1

--  ics.GetComments(1, 10, 3);
Text      SELECT   TOP   10   [ Comment ] . [ ID ] , [ Comment ] . [ ContentID ] , [ Comment ] . [ User_ID ] , [ Comment ] . [ UserName ] , [ Comment ] . [ UserPageUrl ] , [ Comment ] . [ Title ] , [ Comment ] . [ Body ] , [ Comment ] . [ IP ] , [ Comment ] . [ ModifiedDate ]   FROM   [ Comment ]   WHERE  ( [ Comment ] . [ ContentID ]   =   @p0iaahrq8xlay8a AND   [ Comment ] . [ ID ] > ( SELECT   MAX ( [ __T ] . [ ID ] FROM  ( SELECT   TOP   20   [ Comment ] . [ ID ]   AS   [ ID ]   FROM   [ Comment ]   WHERE   [ Comment ] . [ ContentID ]   =   @peyno72o4ia1nq4   ORDER   BY   [ Comment ] . [ ID ] [ __T ] ORDER   BY   [ Comment ] . [ ID ]     
Parameters:
@peyno72o4ia1nq4 [ Int32 ]   =   1
@p0iaahrq8xlay8a [ Int32 ]   =   1


3. FindArray()方法同样需要转换成From()方法, 转换很简单, 直接From().ToArray(EntityType)()就行了....
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值