📄 role.cs
字号:
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;
namespace Library.Data
{
/// <summary>
/// Strongly-typed collection for the Role class.
/// </summary>
[Serializable]
public partial class RoleCollection : ActiveList<Role, RoleCollection>
{
public RoleCollection() {}
}
/// <summary>
/// This is an ActiveRecord class which wraps the roles table.
/// </summary>
[Serializable]
public partial class Role : ActiveRecord<Role>
{
#region .ctors and Default Settings
public Role()
{
SetSQLProps();
InitSetDefaults();
MarkNew();
}
private void InitSetDefaults() { SetDefaults(); }
public Role(bool useDatabaseDefaults)
{
SetSQLProps();
if(useDatabaseDefaults)
ForceDefaults();
MarkNew();
}
public Role(object keyID)
{
SetSQLProps();
InitSetDefaults();
LoadByKey(keyID);
}
public Role(string columnName, object columnValue)
{
SetSQLProps();
InitSetDefaults();
LoadByParam(columnName,columnValue);
}
protected static void SetSQLProps() { GetTableSchema(); }
#endregion
#region Schema and Query Accessor
public static Query CreateQuery() { return new Query(Schema); }
public static TableSchema.Table Schema
{
get
{
if (BaseSchema == null)
SetSQLProps();
return BaseSchema;
}
}
private static void GetTableSchema()
{
if(!IsSchemaInitialized)
{
//Schema declaration
TableSchema.Table schema = new TableSchema.Table("roles", TableType.Table, DataService.GetInstance("Library"));
schema.Columns = new TableSchema.TableColumnCollection();
schema.SchemaName = @"";
//columns
TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
colvarId.ColumnName = "id";
colvarId.DataType = DbType.Int32;
colvarId.MaxLength = 11;
colvarId.AutoIncrement = true;
colvarId.IsNullable = false;
colvarId.IsPrimaryKey = true;
colvarId.IsForeignKey = false;
colvarId.IsReadOnly = false;
colvarId.DefaultSetting = @"";
colvarId.ForeignKeyTableName = "";
schema.Columns.Add(colvarId);
TableSchema.TableColumn colvarName = new TableSchema.TableColumn(schema);
colvarName.ColumnName = "name";
colvarName.DataType = DbType.String;
colvarName.MaxLength = 20;
colvarName.AutoIncrement = false;
colvarName.IsNullable = false;
colvarName.IsPrimaryKey = false;
colvarName.IsForeignKey = false;
colvarName.IsReadOnly = false;
colvarName.DefaultSetting = @"";
colvarName.ForeignKeyTableName = "";
schema.Columns.Add(colvarName);
BaseSchema = schema;
//add this schema to the provider
//so we can query it later
DataService.Providers["Library"].AddSchema("roles",schema);
}
}
#endregion
#region Props
[XmlAttribute("Id")]
public int Id
{
get { return GetColumnValue<int>("id"); }
set { SetColumnValue("id", value); }
}
[XmlAttribute("Name")]
public string Name
{
get { return GetColumnValue<string>("name"); }
set { SetColumnValue("name", value); }
}
#endregion
//no foreign key tables defined (0)
//no ManyToMany tables defined (0)
#region ObjectDataSource support
/// <summary>
/// Inserts a record, can be used with the Object Data Source
/// </summary>
public static void Insert(string varName)
{
Role item = new Role();
item.Name = varName;
if (System.Web.HttpContext.Current != null)
item.Save(System.Web.HttpContext.Current.User.Identity.Name);
else
item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
}
/// <summary>
/// Updates a record, can be used with the Object Data Source
/// </summary>
public static void Update(int varId,string varName)
{
Role item = new Role();
item.Id = varId;
item.Name = varName;
item.IsNew = false;
if (System.Web.HttpContext.Current != null)
item.Save(System.Web.HttpContext.Current.User.Identity.Name);
else
item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
}
#endregion
#region Columns Struct
public struct Columns
{
public static string Id = @"id";
public static string Name = @"name";
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -