ADO.NET Entity Framework Usage

1.Configure DB connection string in web.config

<connectionStrings>
    <add name="elanemeetingdata" connectionString="Server=.\SHAREPOINT;Database=elanemeetingdata;Trusted_Connection=True;" providerName="System.Data.SqlClient" />

</connectionStrings>

2. Add ADO.Entity Data Model(.edmx)

3. Select 'Generate from database'

4. Refer follow sample code:

//class code

   public class EntityOperationLib
    {
        public IQueryable<tb_ElaneMeeting_Users> ReadUsers()
        {
            elanemeetingdataEntities ela = new elanemeetingdataEntities();
            IQueryable<tb_ElaneMeeting_Users> usersQuery = from u in ela.tb_ElaneMeeting_Users
                                                           select u;

            return usersQuery;
        }
    }
//invoke code

      EntityOperationLib entityOperationLib = new EntityOperationLib();
           IQueryable<tb_ElaneMeeting_Users> users= entityOperationLib.ReadUsers();
          var list= users.Select(u => new { u.ID, u.Account, u.Pwd, u.State }).ToList();
          GridView_Data.DataSource = list;
          GridView_Data.DataBind();

.

你可能感兴趣的:(ADO.NET Entity Framework Usage)