Запрос Nhibernate вызывает запрос на обновление - непреднамеренно, почему? - PullRequest
1 голос
/ 05 января 2010

У меня есть следующий код, который вызывает обновление БД как вызов 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();            

        }
    }

Я никогда не ожидал, что какой-то простой выбор вызовет обновление БД! У кого-нибудь есть идеи, почему это так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...