繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> sql2005的xml字段类型在.net中的应用1

sql2005的xml字段类型在.net中的应用1

2007-10-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:今天要介绍的就是sql2005的XML字段类型在.net中的应用。调用过程是:先运用并行化的办法把XML字段类型中的数据转换成Model对象,对Model对象操作后,再运用串行化的方法把Model对象转变成XML格式,最后存储到数据...

今天要介绍的就是sql2005的XML字段类型在.net中的应用。调用过程是:先运用并行化的办法把XML字段类型中的数据转换成Model对象,对Model对象操作后,再运用串行化的方法把Model对象转变成XML格式,最后存储到数据库中。

我认为如果把复杂的业务关系数据存储在XML字段中,可简化数据库的设计,方便业务的处理。

这里写了个小demo:

假如我们有很多店铺信息,每个店铺都有一个ShopID, 所以我们就把同一店铺的信息放在以ShopID命名的文件夹下,当一台服务器放不下时,我们就部署多台,这样每台服务器存储的店铺是不一样的。这些服务器就构成了一个服务器群。出于需要,我们要把这个群复制多个,部署在不同的地区(注意,各个群的信息是相同的)。为了完成这个目的,我们先设计了数据模型 MServerGroup(服务器群信息),MServer(服务器群下的服务器信息),MServerShop(服务器对应的店铺):

///

/// 服务器群信息

///

///

/// 用于存放点播文件服务器群的信息,比如主站的,北京站的,上海站的;各个站的数据相同.

/// 服务器群的目的是分散数据库的压力.

/// 目前只有主站的.

///

[Serializable()]

public class MServerGroup : BaseModelEntity

{

#region private

private int _ServerGroupID;

private string _ServerGroupName;

private MServerCollection _Servers;

#endregion

#region constructor

///

/// 服务器群信息

///

public MServerGroup()

{

}

///

/// 服务器群信息

///

/// 服务器群ID

/// 服务器群名称

public MServerGroup(int _ServerGroupID, string _ServerGroupName)

{

this._ServerGroupID = _ServerGroupID;

this._ServerGroupName = _ServerGroupName;

}

#endregion

#region property

///

/// 服务器群ID

///

public int ServerGroupID

{

get

{

return _ServerGroupID;

}

set

{

this._ServerGroupID = value;

}

}

///

/// 服务器群名称

///

public string ServerGroupName

{

get

{

return _ServerGroupName;

}

set

{

this._ServerGroupName = value;

}

}

///

/// 服务器群下的服务器集合

///

public MServerCollection Servers

{

get

{

return _Servers;

}

set

{

this._Servers = value;

}

}

#endregion

}

///

/// 服务器群下的服务器信息

///

///

/// 用于存放点播文件的服务信息

///

[Serializable()]

public class MServer : BaseModelEntity

{

#region private

private int _ServerID;

private string _ServerName;

private string _IP;

private string _DomainName;

private string _Dir;

private string _Url;

private int _ServerGroupID;

private MServerShopCollection _ServerShops;

#endregion

#region constructor

///

/// 服务器信息

///

public MServer()

{

}

///

/// 服务器信息

///

/// 服务器ID

/// 服务器名称

/// 服务器IP

/// 服务器域名

/// 文件存放目录

/// 文件存放Url

/// 对应的服务器群ID

/// 服务器对应的店铺信息

public MServer(int _ServerID, string _ServerName, string _IP, string _DomainName, string _Dir, string _Url, int _ServerGroupID, MServerShopCollection _ServerShops)

{

this._ServerID = _ServerID;

this._ServerName = _ServerName;

this._IP = _IP;

this._DomainName = _DomainName;

this._Dir = _Dir;

this._Url = _Url;

this._ServerGroupID = _ServerGroupID;

this._ServerShops = _ServerShops;

}

///

/// 服务器信息

///

/// 服务器ID

/// 服务器名称

/// 服务器IP

/// 服务器域名

/// 文件存放目录

/// 文件存放Url

/// 对应的服务器群ID

/// 服务器对应的店铺信息的xml字符串

public MServer(int _ServerID, string _ServerName, string _IP, string _DomainName, string _Dir, string _Url, int _ServerGroupID, string _XMLStrServerShops)

{

this._ServerID = _ServerID;

this._ServerName = _ServerName;

this._IP = _IP;

this._DomainName = _DomainName;

this._Dir = _Dir;

this._Url = _Url;

this._ServerGroupID = _ServerGroupID;

this._ServerShops = Common.Utilities.SerializationHelper.FromXML(_XMLStrServerShops);

}

#endregion

#region property

///

/// 服务器ID

///

public int ServerID

{

get

{

return _ServerID;

}

set

{

this._ServerID = value;

}

}

///

/// 服务器名称

///

public string ServerName

{

get

{

return _ServerName;

}

set

{

this._ServerName = value;

}

}

///

/// 服务器IP

///

public string IP

{

get

{

return _IP;

}

set

{

this._IP = value;

}

}

///

/// 服务器域名

///

public string DomainName

{

get

{

return _DomainName;

}

set

{

this._DomainName = value;

}

}

///

/// 文件存放目录

///

public string Dir

{

get

{

return Dir;

}

set

{

this.Dir = value;

}

}

///

/// 文件存放Url

///

public string Url

{

get

{

return _Url;

}

set

{

this._Url = value;

}

}

///

/// 对应的服务器群ID

///

public int ServerGroupID

{

get

{

return _ServerGroupID;

}

set

{

this._ServerGroupID = value;

}

}

///

/// 服务器对应的店铺信息

///

public MServerShopCollection ServerShops

{

get

{

return _ServerShops;

}

set

{

this._ServerShops = value;

}

}

#endregion

}

///

/// 服务器对应的店铺

///

///

/// 用于存放和服务器对应的店铺

///

[Serializable()]

[XMLRoot(ElementName = "Shop", Namespace = "http://www.linkedu.com.cn/MServerShop.xsd")]

public class MServerShop : BaseModelEntity

{

#region private

private int _ShopID;

private string _ShopName;

#endregion

#region constructor

///

/// 服务器对应的店铺信息

///

public MServerShop()

{

}

///

/// 服务器对应的店铺信息

///

/// 店铺ID

/// 店铺名称

public MServerShop(int _ShopID, string _ShopName)

{

this._ShopID = _ShopID;

this._ShopName = _ShopName;

}

#endregion

#region property

///

/// 店铺ID

///

[XMLAttribute]

public int ShopID

{

get

{

return _ShopID;

}

set

{

this._ShopID = value;

}

}

///

/// 店铺名称

///

[XMLAttribute]

public string ShopName

{

get

{

return _ShopName;

}

set

{

this._ShopName = value;

}

}

#endregion

}

做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。

责任编辑:admin
相关文章