柚子Nan--回归原点

Everything can be as easy as you like or as complex as you need.
posts - 232, comments - 984, trackbacks - 17, articles - 29
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

2005年5月26日

[NHibernate怎样配置数据关联]

NHibernate中对于关系的定义有one-to-one, one-to-many, many-to-one, many-to-many四种,为什么要设置one-to-one, one-to-many, many-to-one, many-to-many呢?在做如下例子的时候我一直在思考,做到一半的时候醒悟了,呵呵,原来就是在Load某个对象的时候,也一并加载其对应关系的对象。就是说你获得了Customer对象以后,Customer.CustomerBank对象的数据也Load进来(当然,你也可以设置Lazy=true,后话)

具体到上述4个关系如何配置,我仅说明一个最简单的,并发现一些常犯的错误!

NHibernate中的一对一关联由“one-to-one”节点定义。也很容易理解,就是一个一对一的关系,例如,一个客户拥有一个而且只能拥有一个银行账户。

 

那么Customer.hbm.xml可以如下定义(当然还有其他的配置方法):

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    
<class name="Data.Customer, Data" table="customer" >
        
<id name="CustomerID" type="Int32" unsaved-value="0">
           
<generator class="identity"/>
       
</id>
        
<property name="CustomerName" column="CustomerName" type="String" length="50"/>
        
<property name="Position" column="position" type="String"/>
        
<one-to-one name="CustomerBank" class="Data.Bank,Data" outer-join="true"/>
    
</class>
</hibernate-mapping>

 

Bank.hbm.xml可以定义如下:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    
<class name="Data.Bank, Data" table="bank" >
        
<id name="CustomerID" type="Int32" unsaved-value="0">
           
<generator class="identity"/>
       
</id>
        
<property name="BankName" column="CustomerName" type="String" length="50"/>
        
<property name="BankBalance" column="position" type="Decimal"/>
    
</class>
</hibernate-mapping>

 

[特别注意]

1 所有的hbm.xml的属性必须设置为Embedded Resource.否则会有异常抛出!

2 注意<one-to-one name="CustomerBank" 这里的CustomerBank,为什么是这个名字,有什么来源吗?答案是显然的,这个名字必须与你在Customer.cs文件中定义的对于访问PropertyBank的名字一致!也就是说,代码必须为:

       public Bank CustomerBank
       
{
           
get{return aBank;}

           
set{aBank = value;}
       }

 

posted @ 2005-05-26 16:41 柚子Nan 阅读(1885) | 评论 (9)编辑

引言,好久没有看到这么畅快的文章了,分析的博古通今,面面俱到,不时让我想起鲁迅先生的文笔,讽刺幽默着时下的一种现象!房地产的主角:政府、开发商和银行;配角:媒体、专家和研究机构,在这样一出大戏中,创造了很多神奇的概念,例如按揭,按揭就是房地产商和银行把你按着,慢慢从你身上揭下一张皮来

感谢作者的妙笔生花,喜欢看楼市,喜欢看好文,特别是怀念鲁迅先生的人不妨读读这个文章!全文请看这里 .

posted @ 2005-05-26 13:53 柚子Nan 阅读(418) | 评论 (0)编辑

今天一个干净的机器安装.Net FrameWork1.1 ,遇到了一个错误,怎么也安装不上!
Google里看了一下,微软的错误真的满天下,变得家喻户晓了。
这不很快就解决了。


Many people experience failure when installing .Net Framework 1.1 Redist. Usually you see a MSI dialog says “Internal Error 2908.”. Later you will see another dialog says “Error 1935. An error occured during the installation of component xxxx. HRESULT: -2147319761”.


The problem usually is because a broken previous install. Rename %windir%\system32\mscoree.dll and re-install usually does the trick.


This works because MSI uses existence of %windir%\system32\mscoree.dll to tell if a .Net framework is already installed. If MSI believes a .Net framework is already installed, it will use the existing .Net framework to install assemblies into GAC. Renaming mscoree.dll tricks MSI to believe .Net framework is not present. In that case MSI will do a fresh install. Fresh installs rarely fail.

FYI: http://blogs.msdn.com/junfeng/archive/2004/01/31/65457.aspx

按照上述的方法果然解决,开始还小心翼翼的把mscoree.dll 备份了一个,然后改了名字,发现安装好以后系统又产生了一个新的mscoree.dll 。后来一切正常,还是非常感谢Junfeng

 

posted @ 2005-05-26 08:58 柚子Nan 阅读(3104) | 评论 (1)编辑