Castle.ActiveRecord 学与练[2]
2008-04-02 17:13 土星的狗狗 阅读(2047) 评论(9) 编辑 收藏 举报就这两天遇到的问题,简单回顾一下,写此篇,希望遇到此类问题的朋友可以参考.
一,朋友问题解决
2008-04-01 14:49 | afh [未注册用户]
请问:如果有多个实体类,在user的构造函数里一个个的添加吗?
有无好办法啊
谢谢
答:
1 protected static bool isInitialized = false;
2
3 protected virtual void InitFramework()
4 {
5 if (isInitialized)
6 return;
7
8 IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
9
10 ActiveRecordStarter.Initialize(Assembly.Load("Training.User"), source);
11
12 isInitialized = true;
13 }
2
3 protected virtual void InitFramework()
4 {
5 if (isInitialized)
6 return;
7
8 IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
9
10 ActiveRecordStarter.Initialize(Assembly.Load("Training.User"), source);
11
12 isInitialized = true;
13 }
这是一个不错的解决方法,并且可以在多个页面里调用这个方法,以达到动态初始化的目的.
二,练习时遇到的问题解决方法
"Could not perform FindAll for",多次遇到这个问题,解决完后总结为以下几种:
1,App.config没有配置正确,借此将我的贴出来供大家参阅
1<?xml version="1.0" encoding="utf-8" ?>
2<configuration>
3 <configSections>
4 <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
5 </configSections>
6 <activerecord>
7 <config>
8 <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
9 <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
10 <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
11 <add key="hibernate.connection.connection_string" value="UID=sa;Password=love;Initial Catalog=CastleTraining;Data Source=GUYZ\GUYZ2000" />
12 </config>
13 </activerecord>
14</configuration>
2<configuration>
3 <configSections>
4 <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
5 </configSections>
6 <activerecord>
7 <config>
8 <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
9 <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
10 <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
11 <add key="hibernate.connection.connection_string" value="UID=sa;Password=love;Initial Catalog=CastleTraining;Data Source=GUYZ\GUYZ2000" />
12 </config>
13 </activerecord>
14</configuration>
2,方法参数内参数没有填写正确
1 public static void DeleteAll()
2 {
3 DeleteAll(typeof(UserEntity));
4 }
typeof(UserEntity)这个参数,我没有填写正确也会抛出这个异常,实是郁闷.2 {
3 DeleteAll(typeof(UserEntity));
4 }
今天就先写到这里吧,下一篇...特性映射
小弟第一次发系列文章,还请高手们多多见谅.
谢谢Terrylee老师的教程对我的帮助.
QQ:22566547;
MSN:LGUYSS@GMAIL.COM;
SITE:WWW.MOBILEBETA.NET