About ASP.NET MVC Repository

AukI

Member
Joined
May 5, 2011
Messages
6
Programming Experience
3-5
I am new in C# and ASP.NET MVC , I worked in VB.NET and windows apps for 3+ years but every thing seems unknown in those areas...
Can anyone guide me where to learn , what repository is .... and why people use below codes to make a repository:

C#:
[Table(Name = "Albums")]
public class Album
{
    [Column(IsDbGenerated = true, IsPrimaryKey = true)]
    public int AlbumID { get; set; }
    [Column]
    public string Title { get; set; }

    private EntitySet<Track> _tracks;

    [Association(Storage = "_tracks", ThisKey = "AlbumID", OtherKey = "AlbumID")]
    public EntitySet<Track> Tracks
    {
        get { return _tracks; }
        set { _tracks.Assign(value); }
    }
}

I don't understand the [Table(Name = "Albums")] part ... what is does ?... can anyone help ... please...

I find those codes in that below link:
asp.net mvc - How to create a fake repository with a 1-to-many association for MVC - Stack Overflow
 
A repository is basically an object that contains data. It abstracts away your application's data store. It has methods to retrieve data and to save data that, from the outside, have no specific connection to any particular database. You ask your repository to get you a list of Thing objects and it gives you a collection of Thing objects. You don't have to know that the data came from SQL Server or Oracle or whatever. You can just think of it as a pool of data with a nice easy interface for getting data in and out.

That Album class would have been intended to mimic one generated by a tool. I'd say that that one was the Entity Framework. The Table attribute on the class indicates that that Album entity class represents a record from the Albums table in the database. Similarly the Column attribute on the properties indicates that that property corresponds to the column of the same name in the Albums table. Tools like the Entity Framework use that metadata to map data from the database to entity classes in your application and back.
 

Latest posts

Back
Top Bottom