EntityFramework

EntityFramework_第1张图片

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

/// <summary>
///Class1 的摘要说明
/// </summary>
public static class Class1<T> where T:class
{
public static void Add(ObjectSet<T> ent, T Model)
{
ent.Attach(Model);
ent.Context.ObjectStateManager.ChangeObjectState(Model, System.Data.EntityState.Added);
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Objects;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{



}
protected void Button1_Click(object sender, EventArgs e)
{
testModel.testEntities tst = new testModel.testEntities();

Class1<testModel.UserInfo>.Add(tst.UserInfo, new testModel.UserInfo { id =Guid.NewGuid().ToString(), password = "aa" });
tst.SaveChanges();
//testModel.testEntities tst = new testModel.testEntities();
//
//tst.AddObject("UserInfo", new testModel.UserInfo { id = "11", password = "aa" });
//tst.SaveChanges();
}
}



 

你可能感兴趣的:(framework)