NHibernateÖ´ÐÐÔʼSQL´úÂëµÄ·½·¨Ð¡½á
ÔÚʹÓÃNHibernate¹ý³ÌÖо³£»áʹÓõ½¸´ÔÓµÄsql²éѯ£¬µ«ÊÇʹÓÃhqlÓֱȽÏÂé·³µÄÇé¿öÏ£¬ÎÒÃÇÍùÍù¶¼»áÏëµ½²ÉÓÃÔʼµÄsqlÀ´Ö´ÐС£µ«ÊÇÈçºÎÀûÓÃNHibernateÀ´Ö´ÐÐsqlÄØ£¿ÎÊÌâÀ´ÁË£¬ÔÚNHibernateÖÐÒ²ÓÐAdoTemplateµÄ·½·¨¿ÉÒÔÖ´ÐÐsqlµÄ£¬µ«ÊÇÕâÀïÒª½éÉܵÄÊÇÁíÍâÒ»ÖÖ·½·¨£ºCreateSQLQuery¡£ÒÔϲ¿·ÖÀý×ÓÔ´×ÔÓÚÍøÂç¡£
ʵÀýÒ»£¨Ô´×ÔÓÚhttp://blog.csdn.net/canduecho/archive/2009/05/04/4149930.aspx£¬¸Ðл²©Ö÷·ÖÏí£©£º
NhibernateÖÐCreateSQLQueryÓ÷¨ÊµÀý£º
Éæ¼°µÄ±í£º
Cake{
Id £¬
CakeName
¡£¡£¡£¡£
}
CakeSize{
CakeId£¬-ΪÍâ¼ü£¬¶ÔÓ¦Cake±íµÄ×Ö¶ÎId
Size
}
£¨ÆäÖÐISession session = NHibernateHelper.GetCurrentSession();£©
Ó÷¨Ò»£¨·µ»ØÊýÖµ£©£º
ISQLQuery query = session.CreateSQLQuery("SELECT COUNT(Id) AS C from Cake").AddScalar("C", NHibernateUtil.Int32);
int c = Convert.ToInt32(query.UniqueResult());
»òint c = query.UniqueResult<int>;//ʹÓô˷½·¨·¢ÏÖsqlÖ´ÐÐÁËÁ½´Î£¬¹Ê²»ÍƼöʹÓá£
Ó÷¨¶þ£¨·µ»Ø¶ÔÏóʵÌ壩£º
ISQLQuery query = session.CreateSQLQuery("select * from cake c").AddEntity("CAKE.DataTransfer.Entities.Cake");
»ò
ISQLQuery query = session.CreateSQLQuery("select * from cake c").AddEntity("c", "CAKE.DataTransfer.Entities.Cake");
»ò
ISQLQuery query = session.CreateSQLQuery("select * from cake c").AddEntity(typeof(Cake));
»ò
ISQLQuery query = session.CreateSQLQuery("select * from cake c").AddEntity("c", typeof(Cake));
»ò
ISQLQuery query = session.CreateSQLQuery("select * from cake c").AddEntity("c", typeof(Cake), LockMode.Write);
IList<Cake> c = query.List<Cake>();
Ó÷¨Èý£¨Á¬±í²éѯ£©£º
ISQLQuery query = session.CreateSQLQuery("select cs.* from cake c join CakeSize cs on cs.CakeId=c.Id")
.AddEntity("cs", typeof(CakeSize));
IList<CakeSize> cs = query.List<CakeSize>();
ÒÔÉÏÊÇÒ»ÖÖ³£¼ûµÄÓ÷¨£¬Í¨¹ý¸ÃÀý×Ó£¬ÏàÐÅ´ó¼ÒÐÄÀïÒ²ÒѾÓиöÊýÁË£¬Ò²Ó¦¸ÃÖªµÀÔõô²Ù×÷Õâ¸ösqlÁË£º£©
µ«Êǹý³ÌÖÐÄÑÃâ»áÓöµ½Ð©ÎÊÌ⣬±ÈÈ磺
ʵÀý¶þ£¨ÎÊÌâ˵Ã÷£©£º
ÎÒÐèÒªÖ´ÐÐÀýÈçÕâÌõsqlÓï¾ä£º
select CreateTime,Address,Password, (case when EmailType = 0 then 'Gmail' when EmailType = 1 t
Ïà¹ØÎĵµ£º
Ò»¡¢¼òµ¥ÊµÓõı¸·Ý·½·¨£º
ÆóÒµ¹ÜÀíÆ÷ÖеÄTools£¬Database Maintenance Planner£¬¿ÉÒÔÉèÖÃÊý¾Ý¿âµÄ¶¨ÆÚ×Ô¶¯±¸·Ý¼Æ»®¡£²¢Í¨¹ýÆô¶¯Sql server AgentÀ´×Ô¶¯ÔËÐб¸·Ý¼Æ»®¡£¾ßÌå²½ÖèÈçÏÂ:
1¡¢´ò¿ªÆóÒµ¹ÜÀíÆ÷£¬ÔÚ¿ØÖÆ̨¸ùĿ¼ÖÐÒÀ´Îµã¿ªMicrosoft SQL Server-->SQL Server×é-->Ë«»÷´ò¿ªÄãµÄ·þÎñÆ÷
2¡¢È»ºóµãÉÏÃæ²Ëµ¥ÖÐ ......
sqlÊý¾ÝÀàÐÍÏê½â
(1)¶þ½øÖÆÊý¾ÝÀàÐÍ
¡¡¡¡¶þ½øÖÆÊý¾Ý°üÀ¨ Binary¡¢Varbinary ºÍ Image
¡¡¡¡Binary Êý¾ÝÀàÐͼȿÉÒÔÊǹ̶¨³¤¶ÈµÄ(Binary),Ò²¿ÉÒÔÊDZ䳤¶ÈµÄ¡£
¡¡¡¡Binary[(n)] ÊÇ n λ¹Ì¶¨µÄ¶þ½øÖÆÊý¾Ý¡£ÆäÖУ¬n µÄÈ¡Öµ·¶Î§ÊÇ´Ó 1 µ½ 8000¡£Æä´æ´¢ñ¿µÄ´óСÊÇ n + 4 ¸ö×Ö½Ú¡£
¡¡¡¡Varbinary[(n)] ÊÇ n λ±ä³¤¶ÈµÄ¶þ½øÖÆÊ ......
SQL Server 2005 ûÓÐSQL Server Management Studio
°²×°visual studio 2005µÄʱºòϵͳҲװÁËSQL 2005¡£Çë×¢Ò⣬Õâʱ°²×°ÉϵÄSQL2005ÊÇExpress°æ±¾µÄ£¬¼È²»ÊÇÆóÒµ°æ£¬Ò²²»ÊÇ¿ª·¢Õß°æ¡£ÕâʱµÄExpress°æÊÇûÓа²×°SQL Server Management Studio µÄ£¬Ö»ÓÐÅäÖù¤¾ß£¬Ò²¾ÍÊÇ˵ÄãÔÚ¿ªÊ¼²Ëµ¥Ö»¿´µÃµ½ÅäÖù¤¾ß¡£
Õâʱ ......
Êý¾Ý¿âÃû£ºEmployee
±íÃû£ºEmployees
uid£ºsa
pwd£ºsa
ÎÊÌâ²¹³ä£º
×îºÃÊÇÌṩSQL SERVER½Ó¿Ú·ÃÎÊÊý¾Ý¿âµÄ´úÂë
Õâ¶Î´úÂëÊÇVS.NET×Ô¶¯Éú³É£¬ÀïÃæÓÐÄÄЩÊDz»ÐèÒªµÄÄØ£¿Ó¦¸Ã°ÑÊý¾Ý¿âÁ¬½ÓµÄ´úÂë·ÅÔÚÄĸöµØ·½ÄØ£¿
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="WebApplica ......
SQLµ±Ç°ÈÕÆÚ»ñÈ¡¼¼ÇÉ
select getdate() //2003-11-07 17:21:08.597
select convert(varchar(10), getdate(),120) //2003-11-07
select convert(char(8),getdate(),112)  ......