Nhibernate选择查询触发更新语句 - 意外,为什么?

时间:2010-01-05 09:34:49

标签: nhibernate

我有以下代码,这会导致DB上的Update更新为调用Commit()。

using (ISession t = DBSessionManager.GetDBSessionController(Database).GetDBSession())
            {
                using (var tx = t.BeginTransaction())
                {
                    var o = t.Linq<Appendix>();
                    o.Expand("Instruments");
                    o.Expand("Language");
                    o.Expand("MifidCompliance");
                    o.Expand("IBAppendix");
                    var ret = (from ss in o where ss.AppendixHierachy.id == hierarchyId select ss).ToList();
                    tx.Commit();
                    return ret;

//this hql also causes the updates
                    string hqlString = "select a from Appendix as a join fetch a.Language as l join fetch a.MifidCompliance as mifid left join fetch a.Instruments i left join  a.IBAppendix as ib where a.AppendixHierachy = " + hierarchyId;
                    IQuery query = t.CreateQuery(hqlString);
                    var items = query.List<Appendix>();                     
                    tx.Commit();
                    return (List<Appendix>)items;
                }             
            }

似乎更新了所有满足限制的附录。(NH Profiler)

UPDATE appendix
SET    appendix = '0x255044462D312E340A25C7E461215928AE3FBD7DF6F17204439AE9AF...' /* @p0_0 */,       creatorEmpId = 0 /* @p1_0 */,
       disclaimerOffset = 0 /* @p2_0 */,
       fileExtension = 'PDF' /* @p3_0 */,
       publishedDate = '2008-10-02T18:34:50.00' /* @p4_0 */,
       reportPositionId = 0 /* @p5_0 */,
       summary = ' summaryText...' /* @p6_0 */,
       thumbnail = '0xFFD8...' /* @p7_0 */,
       title = 'Nitto Denko - Upgrade: Pessimism already priced in' /* @p8_0 */,
       appendixHierarchyId = 12 /* @p9_0 */,
       languageId = 101 /* @p10_0 */,
       MifidComplianceId = 110 /* @p11_0 */
WHERE  id = 337815 /* @p12_0 */

为什么?如果有一些IBAppendix可用,那么它没有更新: 这是映射:

public class IBAppendixMap : ClassMap<IBAppendix>
    {
        public IBAppendixMap()
        {
            Id(x => x.id).GeneratedBy.Foreign("Appendix");            
            Map(x => x.RIXMLProductID);
            References(x => x.Appendix).Column("Appendix_id");
        }
    }

public class AppendixMap : ClassMap<Appendix>
    {
        public AppendixMap ()
        {

            Table("appendix");
            Id(x => x.id).GeneratedBy.Custom(typeof(ATKIdGenerator), a => a.AddParam("TableName", "appendix"));
            References(x => x.AppendixHierachy).Column("appendixHierarchyId").Not.Nullable();
            Map(x => x.appendix);
            Map(x => x.creatorEmpId);
            Map(x => x.disclaimerOffset);
            Map(x => x.fileExtension);
            References(x => x.Language).Column("languageId");
            References(x => x.MifidCompliance).Column("MifidComplianceId");
            Map(x => x.publishedDate);
            Map(x => x.reportPositionId);
            Map(x => x.summary).Length(7000);
            Map(x => x.thumbnailbyte).Column("thumbnail");
            Map(x => x.title);
            HasManyToMany(x => x.Instruments).Table("instAppendix").ParentKeyColumn("appendixId").ChildKeyColumn("instId");
            HasOne( x => x.IBAppendix).Cascade.All();            

        }
    }

我从没想过会有一些简单的选择会导致数据库更新! 有谁想到这是为什么?

0 个答案:

没有答案