Good day,

Is it possible to create a simple entity framework system withou using DAL? or maybe context? direct connection?
let say, i want to extract all my record in gridview.

//assume that this is my formload

    protected form_load()
    {
        if(!isPOstBack)
        {
            getAllRecord(); //mymethod to call the data taht will be place on the gridview
        }
    }



    public void getAllRecord() //this is my method 
    {
            ContactsEntities cont = new ContactEntities();
            gvContacts.DataSource = cont.getContacts();
            gvContacs.DataBind();
    }

my entity class is located on the other class module

let say..

    public class ContactEntities
    {
            public int _id;
            public string name;

            //my properties
            public int ID
            { get ; set ;}

            public string Name
            { get; set; }

    }

i lost when generating the getContacts() just to insert my connection and my query.
i am not familiar with the linq and disconnected layer. i am just a beginner programmer that want to learn basic of entity framework.
I hope that you can help me regarding this

Hi,

I am a bit confused why you would want to effectively rewrite the EntityFramework?
But you could do something like this:

public class Contact
{
    public int Id {get; set;}
    public string Name {get; set}
}

Note you don't need to add field names when doing it like this.

Then in your form:
List<Contact> _list = new List<Contact>();

protected form_load()
{
    if (!IsPostBack)
    {
        addContacts();
        getAllContacts();
    }
}

public void addContacts()
{
    _list<Contact> = new Contact() { Id = 1, Name = "Bob" };
    _list<Contact> = new Contact() { Id = 1, Name = "John" };
}

public void getAllContacts()
{
    gvContacts.DataSource = _list;
    gvContacts.DataBind();
}

But remember without a permanent datasource the List would be lost each time on postback unless you put it in somekind of ViewState or Database. (Anyway this is what I remember as I am a WinForms developer primarily not a WebForms one, anyone feel free to correct me)

Good day MattBerry,

Thanks for the help buddy, You made my mind clear to the output that i want. i am just want to understand the entity framework in a connected layer.

Once again buddy thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.