Fluent Nhibernate and Stored Procedures
来源:互联网 发布:sql 数据库 培训 编辑:程序博客网 时间:2024/06/05 10:16
sql:
DROP TABLE DepartmentGOCREATE TABLE Department(Id INT IDENTITY(1,1) PRIMARY KEY,DepName VARCHAR(50),PhoneNumber VARCHAR(50))GOCREATE PROCEDURE [dbo].[GetDepartmentId] ( @Id INT )AS BEGIN SELECT * FROM Department WHERE Department.Id= @Id ENDGOEXEC GetDepartmentId 1GO
/// <summary> /// 存储过程 /// </summary> /// <returns></returns> static ISessionFactory testSession() { // var config = MsSqlConfiguration.MsSql2005.ConnectionString(@"Server=LF-WEN\GEOVINDU;initial catalog=NHibernateSimpleDemo;User ID=sa;Password=770214;").ShowSql(); // var db = Fluently.Configure() // .Database(config) // .Mappings(a => // { // a.FluentMappings.AddFromAssemblyOf<Form1>(); // a.HbmMappings.AddClasses(typeof(Department)); // }); // db.BuildConfiguration(); //return db.BuildSessionFactory(); ISessionFactory isessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005 .ConnectionString(@"Server=GEOVINDU-PC\GEOVIN;initial catalog=NHibernateSimpleDemo;User ID=sa;Password=520;").ShowSql()) .Mappings(m => m //.FluentMappings.PersistenceModel //.FluentMappings.AddFromAssembly(); .FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) //用法注意 //.Mappings(m => m //.FluentMappings.AddFromAssemblyOf<Form1>()) //.Mappings(m => m //.HbmMappings.AddFromAssemblyOf<Department>()) //.BuildConfiguration() .BuildSessionFactory(); return isessionFactory; } /// <summary> /// 存储过程 涂聚文测试成功。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { try { using (var exc = testSession()) { using (var st = exc.OpenSession()) { if (!object.Equals(st, null)) { //1 string sql = @"exec GetDepartmentId @Id=:Id";// @"exec GetDepartmentId :Id"; IQuery query = st.CreateSQLQuery(sql) //CreateSQLQuery(sql) //GetNamedQuery("GetDepartmentId") //.SetInt32("Id", 1) .SetParameter("Id", 1) .SetResultTransformer( Transformers.AliasToBean(typeof(Department))); //.List<Department>(); var clients = query.UniqueResult();// query.List<Department>().ToList(); //不能强制转化 //IList<Department> result = query.List<Department>(); //不是泛值中的集合 Department dep=new Department(); dep = (Department)clients; //无法将类型为“System.Object[]”的对象强制转换为类型 //2 //var clients = st.GetNamedQuery("GetDepartmentId") // .SetParameter("Id", 1) // .SetResultTransformer(Transformers.AliasToBean(typeof(Department))) // .List<Department>().ToList(); MessageBox.Show(dep.DepName); } } }
0 0
- Fluent Nhibernate and Stored Procedures
- Fluent Nhibernate and Stored Procedures
- Stored Procedures and Functions
- Async and Stored Procedures
- Undocumented Extended and Stored Procedures
- Oracle and Java Stored Procedures
- Stored procedures 1: Find columns and tables
- Stored procedures: Find columns and tables
- Spring, Hibernate and Oracle Stored Procedures
- Stored Procedures in MySQL and PHP
- Stored Procedures
- Using DataAdapters and stored procedures with Sybase and ODBC.NET
- Fluent NHibernate
- Fluent NHibernate
- Privileges for Debugging PL/SQL and Java Stored Procedures
- Debugging PL/SQL and Java Stored Procedures with JPDA
- MySQL Stored Procedures
- Undocumented System Stored Procedures
- 05-百思不得姐(第五天)
- Codeforces E. Bear and Contribution(枚举维护)
- Fluent Nhibernate and Stored Procedures
- ACM_程序设计竞赛:穷举法:DFS(深度优先)
- 静态方法与非静态方法的区别
- Fluent Nhibernate and Stored Procedures
- POJ 3190(Stall Reservations 区间贪心)
- iOS判断字符串中包含数字和字母的几种情况
- Spring AOP注解通过@Autowired,@Resource,@Qualifier,@PostConstruct,@PreDestroy注入属性的配置文件详解
- myHomework Student Planner(学习规划)
- 什么是代码混淆?andriod和android-studio工程如何启用代码混淆功能?
- m_pImageBuffer转换到opencv的一种笨方法
- HDU 5477 A Sweet Journey(亚洲区水题)
- java面向对象特征