- 积分
- 74
- 在线时间
- 55 小时
- 主题
- 6
- 注册时间
- 2013-8-2
- 帖子
- 74
- 最后登录
- 2023-4-4
- 帖子
- 74
- 软币
- 717
- 在线时间
- 55 小时
- 注册时间
- 2013-8-2
|
How to: Map a Database View to a Persistent Class(如何:映射数据库视图到持久化类)
http://documentation.devexpress.com/#Xaf/CustomDocument3281
[url=][/url]
首先创建一个结构体,结构体中的属性为要绑定的视图列
public struct MyViewKey
{
[Persistent("Name")]
public string Name;
[Persistent("PhoneCode")]
public string PhoneCode;
[Persistent("Street")]
public string Street;
[Persistent("City")]
public string City;
[Persistent("FullAddress")]
public string FullAddress;
}
然后将这个结构体当成是Persistent类的KEY
[Persistent("TestView")] //TestView为视图名
public class MyView : XPLiteObject {
[Key, Persistent]
public MyViewKey Key;
public string Name{ get { return Key.Name; } }
public string PhoneCode { get { return Key.PhoneCode; } }
public string Street { get { return Key.Street; } }
public string City { get { return Key.City; } }
public string FullAddress { get { return Key.FullAddress; } }
}
这样就完成了
用到的视图Sql:
SELECT dbo.Country.Name, dbo.Country.PhoneCode, dbo.Address.Street, dbo.Address.City,
dbo.Address.FullAddress
FROM dbo.Address INNER JOIN
dbo.Country ON dbo.Address.Country = dbo.Country.Oid
Address:
CREATE TABLE [dbo].[Address] (
[Street] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[City] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[StateProvince] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[ZipPostal] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[FullAddress] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[OptimisticLockField] [int] NULL ,
[GCRecord] [int] NULL ,
[OID] [int] IDENTITY (1, 1) NOT NULL ,
[Country] [int] NULL
) ON [PRIMARY]
Country:
CREATE TABLE [dbo].[Country] (
[Oid] [int] IDENTITY (1, 1) NOT NULL ,
[Name] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[PhoneCode] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[OptimisticLockField] [int] NULL ,
[GCRecord] [int] NULL
) ON [PRIMARY]
GO
|
评分
-
查看全部评分
|