通过NHibernate创建SQLite触发器 [英] Creating SQLite trigger via NHibernate

查看:64
本文介绍了通过NHibernate创建SQLite触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NHibernate SchemaExport创建一个SQLite数据库.我必须向数据库添加更新,删除和插入触发器. NHibernate可以做到这一点吗?还是我必须手动运行SQL脚本来创建触发器?

I am creating a SQLite database with NHibernate SchemaExport. I have to add update, delete and insert triggers to the database. Is this possible with NHibernate or do I have to run SQL scripts for trigger creation manually?

推荐答案

经过研究,我意识到可以建立Session连接,并且可以从那里运行任何所需的DDL命令.就我而言,应该是:

After some research, I realized it is possible to get the Session connection and from there you can run any DDL command you want. In my case it would be:

       var commandText = new StringBuilder();
        var command = session.Connection.CreateCommand();
        commandText.AppendLine("CREATE TRIGGER books_insert_trg AFTER INSERT ON books ");
        commandText.AppendLine("BEGIN");
        commandText.AppendLine("UPDATE books SET sort=title_sort(NEW.title),uuid=uuid4() WHERE id=NEW.id;");
        commandText.AppendLine("END");
        command.CommandText = commandText.ToString();
        command.ExecuteNonQuery();

这篇关于通过NHibernate创建SQLite触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆