下载地址:
发布 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"
>
<!--
<EntityConfigPath>..\website\EntityConfig.xml</EntityConfigPath>
-->
</
EntityDesignToEntityConfiguration
>
<?
xml version="1.0"
?>
<
configuration
>
<!--
<configSections>
<section name="entityConfig" type="NBear.Common.EntityConfigurationSection, NBear.Common"/>
</configSections>
<entityConfig>
<includes>
<add key="Sample Entity Config" value="~/EntityConfig.xml"/>
</includes>
</entityConfig>
-->
</
configuration
>
原因:
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. 查询方式的改变
原来的方式:
public
Comment[] GetComments(
int
contentID,
int
pageSize,
int
pageNo, OrderByClip orderBy)
{
WhereClip where = WhereClip.All;
if(contentID >0)
{
where = Comment._.ContentID == contentID;
}
return gateway.GetPageSelector<Comment>(where, orderBy, pageSize).FindPage(pageNo);
}
现在改成用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)()就行了....