这个个人搞的框架不知道到底怎么样,做个项目测试下看看,本来想用EF的,大多数人说性能低,所以先放弃,试试这个,一些主要地方我做个摘录
5:多表怎么搞定?
A:视图方式,将多表查询放到数据库里成视图,情况和单表一样使用;
B:自定义查询语句如:
string table = "(select A.*,B.Name from CQ_Album A left join CQ_UserInfo U on A.UserID=U.UserID) v";
MAction action = new MAction(table);
int rowCount;
gvTable.DataSource = action.Select(1, 10, "id>1", out rowCount);
gvTable.DataBind();
action.Close();
MAction action = new MAction(table);
int rowCount;
gvTable.DataSource = action.Select(1, 10, "id>1", out rowCount);
gvTable.DataBind();
action.Close();
当然了,你只要把自定义的sql语句,全放一边去统一管理就行了,界面上就不要出现sql语句了!
本人从新的实体框架上引入SetTo与GetFrom方法,下一篇改造版本将从索引赋/取值中解放,敬请关注:
//原索引设置值:
action.Data[CQ_Album.AlbumName].Value = txtAlbumName.Text;
//改进后成:
action.GetFrom(txtAlbumName);
//原索引读值:
txtAlbumName.Text=action.Data[CQ_Album.AlbumName].Value
//改进后成:
action.SetTo(txtAlbumName);
action.Data[CQ_Album.AlbumName].Value = txtAlbumName.Text;
//改进后成:
action.GetFrom(txtAlbumName);
//原索引读值:
txtAlbumName.Text=action.Data[CQ_Album.AlbumName].Value
//改进后成:
action.SetTo(txtAlbumName);
第二课
接着开始项目实战了,下面示例已经过测试:
1:单行数据填充:
MAction action = new MAction(TableNames.CQ_Album);
if (action.Fill(1))
{
lbText.Text = action.Data[CQ_Album.AlbumName].Value.ToString();
action.Close();
}
if (action.Fill(1))
{
lbText.Text = action.Data[CQ_Album.AlbumName].Value.ToString();
action.Close();
}
2:数据更新:
MAction action = new MAction(TableNames.CQ_Album);
if (action.Fill(1))
{
action.Data[CQ_Album.AlbumName].Value = txtAlbumName.Text;
action.Update();
action.Close();
}
if (action.Fill(1))
{
action.Data[CQ_Album.AlbumName].Value = txtAlbumName.Text;
action.Update();
action.Close();
}
数据更新方法二:
MAction action = new MAction(TableNames.CQ_Album);
action.Data[CQ_Album.AlbumName].Value = txtAlbumName.Text;
action.Update("id=1");
action.Close();
action.Data[CQ_Album.AlbumName].Value = txtAlbumName.Text;
action.Update("id=1");
action.Close();
3:数据删除:
MAction action = new MAction(TableNames.CQ_Album);
action.Delete(2);
action.Close();
action.Delete(2);
action.Close();
数据删除方法二:
MAction action = new MAction(TableNames.CQ_Album);
action.DeleteByWhere("id=2");
action.Close();
action.DeleteByWhere("id=2");
action.Close();
4:数据查询与绑定:
查询所有:
MAction action = new MAction(TableNames.CQ_Album);
gvTable.DataSource = action.Select();
gvTable.DataBind();
action.Close();
gvTable.DataSource = action.Select();
gvTable.DataBind();
action.Close();
分页查询:
MAction action = new MAction(TableNames.CQ_Album);
int rowCount;
gvTable.DataSource = action.Select(1, 10, "id>10", out rowCount);
gvTable.DataBind();
action.Close();
int rowCount;
gvTable.DataSource = action.Select(1, 10, "id>10", out rowCount);
gvTable.DataBind();
action.Close();