Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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


Ïà¹ØÎĵµ£º

SQLºº×Öת»»Æ´Òô

/*
¸ù¾Ýºº×Ö»ñÈ¡È«Æ´
1.Éú³ÉËùÓжÁÒôÁÙʱ±í
2.¸ù¾ÝChinese_PRC_CS_AS_KS_WS ÅÅÐò»ñÈ¡¶ÁÒô
*/
Create function ChineseSpell(@str varchar(100))
returns varchar(8000)
as
begin
declare @re varchar(8000)
--Éú³ÉÁÙʱ±í
declare @t table(chr nchar(1) collate Chinese_PRC_CS_AS_KS_WS,py nvarchar(20))
ins ......

sqlÊý¾ÝÀàÐÍÏê½â

sqlÊý¾ÝÀàÐÍÏê½â
(1)¶þ½øÖÆÊý¾ÝÀàÐÍ
¡¡¡¡¶þ½øÖÆÊý¾Ý°üÀ¨ Binary¡¢Varbinary ºÍ Image
¡¡¡¡Binary Êý¾ÝÀàÐͼȿÉÒÔÊǹ̶¨³¤¶ÈµÄ(Binary),Ò²¿ÉÒÔÊDZ䳤¶ÈµÄ¡£
¡¡¡¡Binary[(n)] ÊÇ n λ¹Ì¶¨µÄ¶þ½øÖÆÊý¾Ý¡£ÆäÖУ¬n µÄÈ¡Öµ·¶Î§ÊÇ´Ó 1 µ½ 8000¡£Æä´æ´¢ñ¿µÄ´óСÊÇ n + 4 ¸ö×Ö½Ú¡£
¡¡¡¡Varbinary[(n)] ÊÇ n λ±ä³¤¶ÈµÄ¶þ½øÖÆÊ ......

SQL Server 2005 ÎÊÌ⣺TCP/IPÎÞ·¨Á¬½Ó

 ¸ÕÅöµ½Õâ¸öÎÊÌâʱ£¬ÒÔΪÊÇÓ¦Ó÷þÎñÆ÷ºÍÊý¾Ý¿â·þÎñÆ÷ûÁ¬Í¨£¬²éÁË°ëÌìµÄÍøÂç½á¹ûÍøÉÏÒ»²é£¬¸úSQL Server 2005Óйأ¬ÄãÌ«ÑôµÄ£¡
  ¿ªÊ¼²Ëµ¥-SQLServer2005-ÅäÖù¤¾ß-SQL Server Configuration Manager-SQLserver2005ÍøÂçÅäÖÃ-MSSQLSERVERµÄЭÒé-Ë«»÷TCP/IPЭÒé
  °ÑIP¸Ä³Éµ±Ç°Ê¹Óõģ¬µ±È»£¬¶Ë¿ÚҲҪȷ±£ ......

.NET »ñÈ¡¾ÖÓòÍøµÄsql server Áбí

SqlDataSourceEnumerator instance =SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
»ò
System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
·µ»ØDatatable
´Ëtable°üº¬ÒÔÏÂËĸö×Ö¶Î
Console.WriteLine("·þÎñÆ÷Ãû = {0}", r ......

¾­µäÓÐÓõÄSQLÓï¾äÊÕ¼¯

1.˵Ã÷£º¸´ÖƱí(Ö»¸´Öƽṹ,Ô´±íÃû£ºa бíÃû£ºb)
SQL: select * into b from a where 11
2.˵Ã÷£º¿½±´±í(¿½±´Êý¾Ý,Ô´±íÃû£ºa Ä¿±ê±íÃû£ºb)
SQL: insert into b(a, b, c) select d,e,f from a;
3.˵Ã÷£ºÏÔʾÎÄÕ¡¢Ìá½»È˺Í×îºó»Ø¸´Ê±¼ä
SQL: select a.title,a.username,b.adddate from table a,(select max(adddat ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ