Tuesday, May 26, 2009

Implementing repository pattern with the ado.net entity model

There are lots of ways to implement repository pattern but with ado.net entity model you can create repository pattern within 10 to 15 minutes.

If you are creating asp.net mvc application then just right click->Model folder->Add->Net Item->select ado.net entity data model.



From database explorer right click and drag your tables to your database explorer. It will create a entity class. For example i have created a notes table for my sample and it will create a notes entity class in my ado.net entity data model.



After creating the entity class not its time to create a interface for repository pattern which will contain my all the operations related to notes entity.

Following is the interface which we will implement use for repository.

namespace DotNetJapsMVC.Models.Respository.Interface
{
interface INotesRepository
{
void CreateNotes(Notes notesToCreate);
void EditNotes(Notes notesToEdit);
void DeleteNotes(Notes notesToDelete);
Notes GetNotes(Guid noteId);
IEnumerable ListNotes();
}
}

Now we will create a class that will implement this repository interface. Here is the coding for that.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotNetJapsMVC.Models.Respository.Class
{
public class NotesRepository:Interface.INotesRepository
{
private DotNetJapsEntities _myEntities = new DotNetJapsEntities();

public void CreateNotes(Notes notesToCreate)
{
_myEntities.AddToNotes(notesToCreate);
_myEntities.SaveChanges();
}

public void EditNotes(Notes notesToEdit)
{
var originalNotes = (from n in _myEntities.Notes
where n.NoteId == notesToEdit.NoteId
select n).FirstOrDefault();

_myEntities.ApplyPropertyChanges(originalNotes.EntityKey.EntitySetName, notesToEdit);
_myEntities.SaveChanges();

}

public void DeleteNotes(Notes notesToDelete)
{
var originalNotes = GetNotes(notesToDelete.NoteId);
_myEntities.DeleteObject(originalNotes );
_myEntities.SaveChanges();
}

public Notes GetNotes(Guid noteId)
{
return (from n in _myEntities.Notes
where n.NoteId == noteId
select n ).FirstOrDefault();
}

public IEnumerable ListNotes()
{
return _myEntities.Notes.ToList();
}

}
}

That's it we have created the repository classes and repository interface. You can use as following in your class or pages.

private  INotesRepository _repository;

public List LoadNotes()
{
 return _repository.ListNotes();
}

Advantage Of Repository Pattern:
  1. Make application loosely coupled so if you want to change the something then you don't need to change everything from scratch.
  2. With the repository pattern we can have nice abstraction which will separate our business logic as well as database logic.
  3. You can prevent dependency injection through the repository pattern.
Happy Programming
Share:
Friday, May 22, 2009

Which .NET Object Relational Mapper is fastest? In .NET Nhibernate,Linq 2 SQL,Entity Framework Or SubSonic, NHibernate

There are lots of ORM(Object Relational Mapper) tools are available for the Microsoft.NET like linq 2 sql, ado.net entity framework, nhibernate, subsonic and so many others. Developer often confuses which technlogy he should choose but i think a developer should deternmine his requiremnt first then he has check the pros and cons of every tool there .

I have used ado.net entity framework for my application as i like it most and its easy to use.
Following are some good article which will help you to choose right orm tool for your applications.

http://ayende.com/Blog/archive/2007/06/03/On-SubSonic-amp-NHibernate.aspx

http://blog.wekeroad.com/blog/aspnet-mvc-choosing-your-data-access-method/

http://dotnet.netindonesia.net/?0::41743

http://geekswithblogs.net/diadiora/archive/2009/01/12/best-.net-orm-tool.aspx


http://madgeek.com/Articles/ORMapping/EN/mapping.htm


Happy Programming...
Share:
Thursday, January 15, 2009

Member of class - Object Oriented Programming


Definitions Of Object:
An object is combination and collection of data and code designed to emulate a physical abstract enmity.You can create number object of class. The properties, Variable and Methods define in class are called Members of class.

  1. Private Member Of Class: Private member of a class have strict access control Only the member function of same class can access this members.
  2. Protected Member of Class: A Protected member is accessible to member of its own calls and to any of the class member in a derived class.
  3. Public Member Of Class: A public member of class can be accessible from any where.
  4. Public and Private Static Member Of a Class: The static member of a class can be access without creating a object of class. While to access other member of class you have to create a object of class. The public static member can be accessed using access specifier while private static member can be accessed only the member functions.
Inheritance and Member Accessibility:
  1. A private member is accessible only to members of the class in which private member is declared. They cannot be inherited
  2. A private member of the base class can be accessed in the derived class through the member of the base class.
  3. A protected member is accessible by member of its own class and to any of the class member in a derived class.
Share:

Diffrent Type Of Inheritance- Object Oriented Programing

Following are different type of inheritance..
1) Single Inheritance:
Derivation of class from only one base class is called single inheritance.
2) Multiple Inheritance:
Derivation of class from several base class is called multiple inheritance.
3) Hierarchical Inheritance:
Derivation of several classes from a single class is called hierarchical inheritance.
4) Multilevel Inheritance:
Derivation of a class from another derived class is called multiple inheritance.
5) Hybrid Inheritance:
Derivation of a class involving more then one form of inheritance is called hybrid class.
6) Multi path Inheritance:
Derivation of a class from another derived classes which are derived from the same base class is called multi path inheritance.


Share:
Wednesday, January 14, 2009

Basic Concept Of Object Oriented Programming

Following are the basic concepts of object oriented programming.
1) Objects:
Object are the basic run time entities in the object oriented system. They may represent a person, a palace, a bank account, a table data or anything that a program can handle.
2) Classes:
A class encloses both the data and function that operate on the data into a single unit.
3) Data abstraction and Encapsulation:
The wrapping of data and function in a single unit is know as encapsulation. It is a mechanism that associate into the single unit and keeps them safe from external interference and misuse.
Abstraction refers to the act of representing essential features without including the background details or explanations.
4) Inheritance:
Inheritance is the process by which objects of one class acquire the properties of objects of another class.
5) Polymorphism:
Polymorphism means ability to take more then one form. For example as operation may execute different behaviour in different conditions. The behaviour depends on type of data used in operations.
6) Dynamic Binding:
Binding refers to the linking of a procedure call to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not know until the time of call at run time. Virtual functions are the best examples of dynamic binding.
7) Message Communications:
An object oriented program consists of a set of objects that communicate with each other. Object
communicate with one another by sending data receiving information much same way as people passes messages to one another. A message for an object is a request for the execution of a procedure and therefore will invoke function in the receiving object that generates desire results.
8) Extensibility:
It is a feature which allows the extension of the functionality of the existing software components.
9) Delegation:
It is a alternative to the class inheritance. Delegation is a way of making object composition as powerful as inheritance. In delegation two objects are invoked in handling a request, receiving object delegates operation to its delegate. This is analogues to the child class sending a request to the parent class.
10) Generaticity:
It is a technique for defining software components that have more then one interpretation depending on the typoe of parameters.
Share:

Object Oriented Interview Question Part 1- Benefits Of Inheritance

Following are the benefits of the inheritance...
  1. Through inheritance we can eliminate the redundant code and extend the user of the existing classes.
  2. We can build program from the standard working modules that can communicate with the one another rather then having start writing code from beginning.
  3. It is possible to have multiple instances of objects of class without any interface.
  4. It is easy to partion the work.
  5. Object oriented system can be easily upgraded from the small to the large systems.
  6. Easily modifying and extending implementations of components without having to recode everything from scratch.
Share:
Tuesday, January 13, 2009

Happy New Year 2009

Hello Guys,

I am jalpesh vadgama wishing you a very happy and healthy new year ahead. Sorry i was busy with my projects so not able to post anything related to dot net. Now i am back with the all the things and promise to be regular post. If you want to listen anything from me then please post comment.

Last year was hectic to me as lots of things are going on now my house is also shifted and i have broadband connection at my home. We can have conservation regularly.
Share:
Monday, August 11, 2008

How to add service reference dynamically from user control? Microsoft Ajax

First, Create a web page default.aspx and put the html code as following..

---------------------------------------------------------------------------
<asp:ScriptManager ID="MainScriptManager" runat="server">
</asp:ScriptManager>
--------------------------------------------------------------------------

Now, Create a usercontrol my first user control

Create a function called AddScriptReference as following...

'--------------------------------------------------------------------------
private void AddScriptReference()
{
     ScriptManager scriptManger = ScriptManager.GetCurrent(this.Page);
     if (scriptManger != null)
     {
         ServiceReference serviceReference = new ServiceReference();
         serviceReference.Path="~/MyWebService.asmx";
         serviceReference.InlineScript = false; 
         scriptManger.Services.Add(serviceReference);   
     }
     else
     {
         throw new Exception("Script Manager Not Found");
     }
}
'--------------------------------------------------------------------------
Then override controls init event as following...

'--------------------------------------------------------------------------
protected override void OnInit(EventArgs e)
{
     AddScriptReference();
     base.OnInit(e);
}
'--------------------------------------------------------------------------

Share:
Thursday, July 31, 2008

What is LINQ? LINQ Developer Resources

LINQ is Language Integrated query. It is a integral part of visual studio 2008 and Microsoft .NET Framework 3.5. It is object to database mapping technology thorough which you can query any type of collections of object,XML of database.

 

Recently I am goggling about the LINQ and I have found following great resources for developers:

LINQ Resources:

Linq for Oracle:
----------------
http://broersa.wordpress.com/2008/05/22/linq-for-oracle-sample/

 

.NET 2.0 Or higher transaction model to use it with linq:
----------------------------------------------------------
http://www.simple-talk.com/dotnet/.net-framework/.net-2.0-transaction-model/

 

How to use transaction with linq:
--------------------------------
http://chiragrdarji.wordpress.com/2007/08/25/how-to-use-transaction-in-linq-using-c/

 

Inside the linq datacontext site to better understanding of linq:
-----------------------------------------------------------------
http://dotnetslackers.com/articles/csharp/InsideTheLINQToSQLDataContextClass.aspx

 

Linq to SQL(part 1 to 7 -Total Understanding of linq):
------------------------------------------------------
http://aspalliance.com/1430_LINQ_to_SQL_Part_6__Retrieving_Data_Using_Stored_Procedures_.1

 

A good article about-LINQ to SQL : Using Transaction:
-----------------------------------------------------
http://blogs.msdn.com/wriju/archive/2007/08/06/linq-to-sql-using-transaction.aspx

 

Using LINQ in ASP.NET (Part 1)- A Four part series from bipin joshi:
--------------------------------------------------------------------
http://www.dotnetbips.com/articles/56f8f29d-2617-4f99-a8b4-977703ebf780.aspx

 

The Linq Project:
----------------
http://msdn.microsoft.com/en-us/vbasic/aa904594.aspx

 

What is linq:
------------
http://en.csharp-online.net/Introducing_LINQ%E2%80%94What_Is_LINQ
http://www.dotnetspider.com/resources/19939-What-LINQ.aspx.aspx

 

Scott gu's Multipart Series about linq:
--------------------------------------
http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

 

Linq to xml:
-------------
http://sandeep-aparajit.blogspot.com/2007/12/what-is-linq.html

Share:
Tuesday, July 15, 2008

Benefits of DotNetNuke

Dotnetnuke is open source content management system which provides various kind of functionality for content management and modular development. It provides a very good platform based Microsoft.net technologies to create web portals on the fly. You can create portal and subportals on a fly. Within some minutes. Here is another benefits of Dotnetnuke which found from the here.

  • Easy Web site administration: While working on this framework no programming knowledge is required. Clients can generate, supervise and publish web content without requiring any technical skill level.
  • Ready to use: DotNetNuke is user-friendly framework and is built in such a way as to allow users to deal with all parts of their projects. A well worked out user interface allows an easy operation.
  • Advanced Features: The advanced features in DotNetNuke exceed the features in your homegrown applications. Moreover it is a constantly evolving with multi-functionality to cater end-user requirements. It also saves development time.
  • Strength: The administrative options are skillfully divided between host level and individual portal level. In one hosting account the administrator at DotNetNuke supports multiple portals or sites- each with its own look.
  • Powerful Tools: DotNetNuke comes with a set of powerful tools. These built in tools provide multi-functionality for security, site designing, hosting, site membership options etc. There are various other features that can be manipulated as per your needs with these tools.
  • Network of Support: A Core Team of developers is always there to support DotNetNuke. Online Forums, blogs, online help and various websites give DotNetNuke a dedicated network of support.
  • Easy Installation: DotNetNuke.com provides the free download software and an install.pdf with install instructions for the latest version of DotNetNuke. DotNetNuke can be made running within minutes.¼LI>Multi-Language Localization: DotNetNuke supports a multi-language localization that allows the websites built on it, to be translated into any language.
  • Licensed Open Source Software: DotNetNuke 3.0 is available for free download. The full application source code and sub-projects are distributed under a standard BSD open source license; providing the maximum freedom in both non-commercial and commercial environments.
  • Increase Profits Opportunities: DotNetNuke is module based. So you can build up various unique modules and sell them to your clients. Besides this, you can also go commercial with site templates, database options etc.
  • Latest Technology: The working of DotNetNuke utilizes modern day technology- ASP.NET 2.0, Visual Web Developer, Visual Studio 2005 and SQL Server 2005, thus giving the users a hands on to the latest technology.
  • Advanced CMS: DotNetNuke has built-in tools to create the most complex content management systems. Moreover, many options of extending and customizing the site are also available.
  • Established: DotNetNuke is a now a trademark in web designing. It is a popular brand in the open source community. With over 250,000 registered users and a talented team of developers. Through end-user feedback and real world trial DotNetNuke continues to grow.
  • Easy to integrate: With its flexible infrastructure, DotNetNuke is easy to integrate within your conventional processes.
  • Priority on security: Emphasis placed on validation, encryption, “bug” tracking and potential threats provides a secure way to build websites.
  • Fully customizable: Changes can be made to portals at all levels – from basic stylesheet elements like font type, color, and bullet points, to overall site appearance. New skins and module containers can be easily applied to the site with no repercussion on content.

for more details about dotnetnuke you can visit following sites.

www.dotnetnuke.com

http://www.datasprings.com/Resources/ArticlesInformation/WhymovetoDotNetNuke/tabid/736/language/en-US/Default.aspx

Share:

How to convert a class library project into web application? What is web application? Difference between website and web application?

Web applications are there Visual Studio.Net 2003. After launch of Visual studio.Net Microsoft has introduced a new concept like website. But after huge demands community Microsoft has reintroduced Microsoft web applications project which is very similar to webapplication in vs.net 2003. With visual studio.net 2008 you will have both the options webapplication and website to create asp.net application. First we discuss the difference between it.

 

Difference between webapplication and website.

The main difference is that website project can be complied on the fly. You need to compile every time when you changed the code. While in webapplication you have compile solutions and create binary files(.DLL) in the code then you can have new code effect in application.It will have all the code in bin folder as DLL.

Website project can be opened without a project solution file while webapplication projects can not opened without a solutions.

 

A website usually refers to the front-end interface through which the public interact with your business online.Website's are typically informational in nature with a limited amount of advanced functionality. Simple websites consist primarily of static content where the data displayed is the same for every visitor and content changes are infrequent. More advanced websites may sport features such as Commerce, content management and interactive content.


Where AS A web application or Rich Internet Application (RIA) usually includes a website component but features additional advanced functionality to replace or enhance existing business processes. The interface design objective behind a web application is to simulate the intuitive, immediate interaction a user experiences with a desktop application.


Web applications frequently integrate with existing business IT infrastructure such as accounting packages, stock management systems, ERP, etc.

 

You can download web application projects for visual studio 2005 from the following location.

http://msdn.microsoft.com/asp.net/reference/infrastructure/wap/

 

I have found a very great link to convert existing class library or another project into web application..Here is the link..

http://msdn.microsoft.com/asp.net/reference/infrastructure/wap/

Share:
Wednesday, May 21, 2008

Localization in asp.net

I am googling about the localization in asp.net 2.0 and higer version and i found lots of good link for that.

Here is the collection of good link if anybody is looking for it.

ASP.NET 2.0 Localization (Video, Whitepaper, and Database Provider Support)
http://weblogs.asp.net/scottgu/archive/2006/05/30/ASP.NET-2.0-Localization-_2800_Video_2C00_-Whitepaper_2C00_-and-Database-Provider-Support_2900_.aspx

ASP.NET 2.0 Localization Features: A Fresh Approach to Localizing Web Applications
http://msdn.microsoft.com/en-us/library/ms379546(VS.80).aspx

ASP.NET AJAX Localization Slides and Code
http://seejoelprogram.wordpress.com/2008/03/06/aspnet-ajax-localization-slides-and-code/

Building Multilingual Web Sites with ASP.NET
http://www.beansoftware.com/ASP.NET-Tutorials/Globalisation-Multilingual-CultureInfo.aspx

Globalization and localization demystified in ASP.NET 2.0
http://www.codeproject.com/KB/aspnet/localizationByVivekTakur.aspx

Enterprise Localization Toolkit
http://msdn.microsoft.com/en-us/library/aa479334.aspx

How to build Multi-Language Web Sites with ASP.NET 2.0 and VS.Net 2005
http://www.dotnetheaven.com/UploadFile/mosessaur/aspnetlocalization03232006045335AM/aspnetlocalization.aspx

Introduction to Localization in ASP.NET 2.0
http://www.west-wind.com/presentations/wwDbResourceProvider/introtolocalization.aspx

Localization in ASP.NET 2.0
http://aspalliance.com/821

Localization practices for .NET 2.0: It's still about the architecture
http://searchwindevelopment.techtarget.com/tip/0,289483,sid8_gci1278147,00.html#

Arabization: Localization/Globalization in ASP.Net 2.0
http://www.c-sharpcorner.com/UploadFile/munnamax/Localization03172007031927AM/Localization.aspx

Creating multilingual websites - Part 1
http://www.codeproject.com/KB/aspnet/localization_websites.aspx

Localization in ASP.NET 2.0
http://www.ondotnet.com/pub/a/dotnet/2005/08/08/localizingaspnet20.html

Resources and Localization in ASP.NET 2.0
http://msdn.microsoft.com/en-us/magazine/cc163566.aspx

Internationalizing Your Application-ASP.NET QuickStart Tutorial

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/default.aspx

Share:
Monday, April 28, 2008

Page.RegisterClientscriptBlock was not working with rad Ajax panel

I have using rad ajax panel to apply ajax on my web applications. And I have found that Page.RegisterClientScriptBlock was not working with rad ajax panel. I have found a very good solutions for them. There is a property called "EnableOutsideScripts". I have set it true.. Now it is working fine ...
Share:
Wednesday, April 9, 2008

Microsoft Enterprise library 4.0 CTP Release

For some days ago microsoft has release Microsoft enterprise library 4.0 CTP.

This release has been adapted to work with WMI version 2.0 and version 3.5 of the .NET Framework.

For more Details visit following links..

http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=entlib&ReleaseId=12142

http://blogs.msdn.com/agile/archive/2008/03/31/enterprise-library-4-0-march-2008-ctp-released.aspx

Here are the system requiement :

  • Microsoft Windows XP Professional, Windows Server 2003, Windows Server 2008, or Windows Vista operating system
  • Microsoft .NET Framework 3.5 or higher.
  • Microsoft Visual Studio 2008 development system (any of the following editions): Standard Edition, Professional Edition, Team Edition for Software Developers, Team Edition for Software Testers, Team Edition for Software Architects, or Team Suite
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews