33_pgcon2008-introducingnpgsql
DESCRIPTION
33_PGCON2008-IntroducingNpgsqlTRANSCRIPT
![Page 1: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/1.jpg)
©2005 Wiseknot. All rights reserved. 1PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Introducing NpgsqlA .Net Data Provider for Postgresql
PGCON 2008 – Ottawa – Canada
Francisco Figueiredo [email protected]
Hiroshi [email protected]
Josh [email protected]
![Page 2: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/2.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Topics
HistoryFeaturesInternalsAbout Npgsql in JapanDeployment of NpgsqlGnu/Linux <-> Windows
![Page 3: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/3.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Topics
SamplesConsoleImagemake Large ObjectSystem.Transactions DemoEntity Framework
CommunityFuture work
![Page 4: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/4.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
History
Work began on Npgsql in May 5, 2002
This was when I fist started coding
At that time, I was already a big fan of OpenSource philosophyI was only an spectator.
● I wanted to contribute
I wanted a project to work on a network protocol
![Page 5: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/5.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
History
I had a look at Postgresql and MySqlI decided by Postgresql because of the excellent protocol documentation!Where Npgsql name came from?
● Miguel de Icaza once asked me that
![Page 6: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/6.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
History
By the time Npgsql started, it was common to prefix projects with N (for .Net)
● Nant● Nhibernate● NUnit
So I thought about: N(.Net) pgsql (Postgresql)
![Page 7: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/7.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
History
Beginning of 2003, Daniel Morgan from Mono project told me they choose Npgsql as official Postgresql Data Provider That made us be sure we were in the right track! :)
![Page 8: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/8.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Features
Npgsql is done with 100% C#There is no dependency on external libraries
● This was by design, so it would be easier to install and deploy
Works on Mono and MS .Net Runtimes. This means it works on Gnu/Linux, Windows, MacOS and any other supported platform
![Page 9: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/9.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Features
Supports Postgresql server from 7.3 and aboveImplements protocol versions 2 and 3You can use Npgsql to send usual queries: select, insert, update and delete
![Page 10: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/10.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Features
Has support for Large Object API
● Hiroshi Saito will show an example which uses it
Has support for clear and md5 passwords
● Starting with Npgsql2 beta3, we added support for SSPI authentication on windows. Thanks Brar Piening patch
![Page 11: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/11.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Internals
Today we have two versions of Npgsql:We have Npgsql 1.0 which is now only maintained with critical bug fixesAnd there is Npgsql 2.0 which is being actively developed and targets .Net 2.0+ runtime
![Page 12: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/12.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Internals
We have project files for Nant, Monodevelop, VS.Net 2005 and VS.Net 2008 The easiest way to compile Npgsql is grab cvs or source code release, enter Npgsql/src folder and type nantStarting with Beta3, thanks to Jon Hanna's work, Npgsql now returns data on demand to client
![Page 13: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/13.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Internals
Previous versions got all data from server before making it available to clientThis behavior has a big impact when dealing with large resultsets
![Page 14: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/14.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Examples
This is a simple console example:
public static void Main(String[] args) { NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=joe;Password=secret;Database=joedata;"); conn.Open(); NpgsqlCommand command = new NpgsqlCommand("select version()", conn); String serverversion; serverversion = (String)command.ExecuteScalar(); Console.WriteLine("PostgreSQL server version: {0}", serverversion); }
![Page 15: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/15.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
![Page 16: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/16.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
About Npgsql in Japan
![Page 17: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/17.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Npgsql Document
![Page 18: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/18.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Npgsql in PostgreSQL 8.2 and under is used by VC#2005.
Deployment of Npgsql
![Page 19: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/19.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Deployment of Npgsql
Npgsql in PostgreSQL 8.3 installer is used by VC#2008.
![Page 20: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/20.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Linux<->WindowsLinux(OpenSUSE 10.1) WindowsXP SP2
Use of the same binary and source is possible.
![Page 21: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/21.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
OpenSUSE 10.1 (Linux)
![Page 22: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/22.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Npgsql2 .NET2.0
・ Npgsql.NpgsqlFactory
- DbProviderFactories
![Page 23: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/23.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Npgsql2 .NET2.0
・ Npgsql.Security
NpgsqlMembershipProvider
NpgsqlProfileProvider
NpgsqlRoleProvider
※ ログインソリューションを提供
![Page 24: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/24.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
ImageMakeLargeObject
NpgsqlTransaction t = Polacz.BeginTransaction();
LargeObjectManager lbm = new LargeObjectManager(Polacz);
LargeObject lo = lbm.Open(takeOID(idtowaru),LargeObjectManager.READWRITE);
byte[] buf = new byte[lo.Size()];
buf = lo.Read(lo.Size());
MemoryStream ms = new
MemoryStream();
ms.Write(buf,0,lo.Size());
lo.Close();
t.Commit();
![Page 25: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/25.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
![Page 26: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/26.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
System.Transactions in Npgsql
.Net and Mono
![Page 27: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/27.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Using System.Transactions
using (TransactionScope scope = new TransactionScope()){ using (NpgsqlConnection connection = new NpgsqlConnection(connectionString)) { // auto enlist in transaction connection.Open(); // perform transacted operations } scope.Complete();
}
![Page 28: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/28.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Distributed Transactions
Requires Windows and the Microsoft CLR.Requires MSDTC to support managing the distributed transaction.Does not yet support recovery from failure in the middle of the two phase commit.
![Page 29: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/29.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
System.Transactions Demo
Demo distributed transaction with two connectionsDemo recovery from failure during two phase commit
![Page 30: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/30.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Entity Framework
ADO.NET for .NET 3.5 SP1
*portions of presentation reused from DevDays 2007
with permission from Microsoft
![Page 31: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/31.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
The Entity Framework
ADO.NET Providers
ADO.NET 2.0
The Entity Data Model
Language Integrated Query (LINQ)
Bottle Winery
Supplier
<book> <title/> <author/> <year/> <price/></book>
ADO.NET Providers
Entity Client
Object Services
LINQ over Entities
ADO.NET Entity Framework
![Page 32: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/32.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
ADO.NET Data ProvidertADO.NET Data Provider
Entity Framework Overview
ADO.NET Data Provider
Object Services
LINQ to Entities
EDMMetaData
Store Schema
ConceptualSchema
ObjectMetadata
OCMap
CSMap
CQT
DataReader
DataReader
IEnumerable<T>ESQL
NativeSQL
CQT
ESQL
LINQ
EntityClient Data Provider
Client View Engine CQT
![Page 33: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/33.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
EDMGEN.EXE• Generates the model files• Model.ssdl (Store Schema Definition Language)
● Describes tables and columns which map to Entities and Relationships• Model.csdl (Conceptual Schema Definition Language)
● Describes the Entity Data Model (incl. EntitySets, EntityTypes, Associations & AssociationsSets)
• Model.msl (Mapping Specification Language)● Describes how the Entity Framework maps between the Conceptual
Model (CSDL) and the logical Storage Schema (SSDL)• Model.cs or Model.vb
● Partial class implementing the model created
![Page 34: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/34.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Entity Framework Demo
Generate ModelESQL with objectsLINQ with objects
LINQ with relationship restrictions
![Page 35: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/35.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Future of Npgsql
Npgsql 2.0 release (see current betas)
Includes support for .NET 2.0Includes support for .NET 3.5 SP1
Custom Type supportBetter Visual Studio integration for 2005 and 2008 (DDEX support).
![Page 36: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/36.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Community
Npgsql has a very active communityProject is hosted at pgfoundry.org. Previously it was hosted at gborg.orgIn March, we registered npgsql.org domain
● Thanks Magnus for registrar tip! :)
![Page 37: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/37.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Community
pgfoundry.org provided us with a great user interface which were forums. They improved very much user interactionUsers are very active at Npgsql forumsWe get great feedback thereMany users provide valuable bug reports and fixes as well!!
![Page 38: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/38.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Community
We have some friendly urls redirections:
http://project.npgsql.orghttp://documentation.npgsql.orghttp://forums.npgsql.orghttp://cvs.npgsql.org
![Page 39: 33_PGCON2008-IntroducingNpgsql](https://reader034.vdocuments.net/reader034/viewer/2022051218/563db897550346aa9a951b08/html5/thumbnails/39.jpg)
PGCON2008 – Ottawa – Copyright© 20022008 Npgsql Development Group. All Rights Reserved.
Obrigado – Arigato – Thank you
References:http://www.microsoft.com/japan/msdn/http://www.monoproject.com/Main_Page
http://www.npgsql.org/
Francisco Figueiredo [email protected]
Hiroshi [email protected]
Josh [email protected]