Wednesday, November 2, 2011

NHibernate

Feature summary
NHibernate's primary feature is mapping from .NET classes to database tables (and from CLR data types to SQL data types). NHibernate also provides data query and retrieval facilities. NHibernate generates the SQL commands and relieves the developer from manual data set handling and object conversion, keeping the application portable to most SQL databases, with database portability delivered at very little performance overhead.

NHibernate provides transparent persistence for Plain Old CLR Objects (POCOs). The only strict requirement for a persistent class is a no-argument constructor, which does not have to be public. (Proper behavior in some applications also requires special attention to the Equals() and GetHashCode() methods.)

What is new in NHibernate 3.2Some of the new Features are

Mapping by code: fluent configuration, no more .hbm.xml files required;
Subselect: ability to map SQL views as entities;
HQL paging: TAKE and SKIP on HQL;
Integrated bytecode provider: one less DLL to deploy.

Sample Code

Here a code snippet to save and retrieve an object using NHibernate:

////Save a Customer
using (var session = sessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(new Customer { Id = Guid.NewGuid(), FirstName = "Bill", Age = 50 });
transaction.Commit();
}
}

////Retrieve the Customer
using (var session = sessionFactory.OpenSession())
{
var customer = session.Query().Single(c => c.Id == id);
}

Ref:
http://en.wikipedia.org/wiki/NHibernate

Saturday, May 7, 2011

Generic Methods

Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations, as shown here:

// Declare the generic class
public class GenericList
{
void Add(T input) { }
}
class TestGenericList
{
private class ExampleClass { }
static void Main()
{
// Declare a list of type int
GenericList list1 = new GenericList();

// Declare a list of type string
GenericList list2 = new GenericList();

// Declare a list of type ExampleClass
GenericList list3 = new GenericList();
}
}

Wednesday, July 7, 2010

CheckBox unchecks inside DataGridTemplateColumn

When we use checkbox or radio button in the datagridtemplatecolumn, in silverlight datagrid. its load the each row when its appears inside the datagrid so it’s using the same object as the other row.

So if we want to show all the rows into the single shot we can edit the datagrid template and put that rowpresenter inside the scrollviewer.

This issue also discussing here and I also wrote there the same think.

Saturday, June 19, 2010

Get table from XML

I was sterling to convert the xml and get the table from the XML. But I did some work around and I am successfully done that here I am writing the stored procedure from the we can get the table from the XML that may help you any time..

Create PROCEDURE [dbo].[GetTableFormXML]
-- XML where from we need table

@xml xml
AS
BEGIN

SET NOCOUNT ON;
declare @OutputTable TABLE
(
nodeName varchar(max),
nodeValue varchar(max)
)
-- Insert statements for procedure here
DECLARE @xmldoc int,@tbl sysname,@sql nvarchar(4000),
@sql1 nvarchar(4000),@intCount int,@intFlag INT,
@Valuetext varchar(max)

set @Valuetext =''

declare @tempTable AS table( nodeName varchar(max))
declare @strValue as Table(value varchar(max))

EXEC sp_xml_preparedocument @xmldoc OUTPUT, @xml -- load the xml data
insert @tempTable
--Select all the node values
SELECT nodeName = localname FROM OPENXML (@xmldoc, '//.') where parentid is not null and nodetype = 1 --Select all the node accept root node and the attribute
DECLARE tblcur CURSOR STATIC LOCAL FOR
SELECT nodeName FROM @tempTable
OPEN tblcur
SET @intFlag = 1
WHILE (@intFlag <= (SELECT COUNT(*) FROM @tempTable)) BEGIN FETCH tblcur INTO @tbl IF @@fetch_status <> 0
BREAK
SELECT @sql = N'SELECT * FROM OPENXML (@xmldoc, ''//'+ @tbl +''') WITH (Col1 varchar(200) ''text()'')'

set @intFlag = @intFlag + 1

insert @strValue EXEC sp_executesql @sql,N'@xmldoc int',@xmldoc -- Select the node value


INSERT INTO @OutputTable (nodeName, nodeValue)
SELECT @tbl, value
FROM @strValue

delete @strValue -- Clear the data again

END
EXEC sp_xml_removedocument @xmldoc
select * from @OutputTable
END