Tuesday, May 26, 2009

Microsoft Visutal Studio 2010 Beta Available for download now

We all .NET developers are waiting for the visual studio .NET 2010 for long time. Microsoft just have enabled download for all beta users. Following is the link for downloading the visual sutdio 2010.

http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx.

From this link you will know all the things related to visual studio 2010.

Following are the some glimpse of the features of visual studion 2010.

  1. F# Support
  2. Java Script code compilation and debugging
  3. JQuery is included in visual studio 2010
  4. UML
  5. Better display of code in editor.
  6. Parrallel Programing facilities.
Share:

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:

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