本文整理汇总了C#中BaseEntity.GetListDataTable方法的典型用法代码示例。如果您正苦于以下问题:C# BaseEntity.GetListDataTable方法的具体用法?C# BaseEntity.GetListDataTable怎么用?C# BaseEntity.GetListDataTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseEntity
的用法示例。
在下文中一共展示了BaseEntity.GetListDataTable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Oracle or SQl are same code :
// We have table in database :Name is Test and Columns (ID - Name - Price - Date) with the same sort and names
// Table in sql or Oracle : (ID : int , Name : nvarchar(50) , Price : numeric(18,3) , Date : datetime)
// in c# class : (ID : int , Name : string , Price : decimal , Date : DateTime)
// Notice : Table Name = Class Name , Columns Names = Properties Names and Columns sorts = Properities sorts are Neccessary for working fine.
BaseEntity<Test> dc = new BaseEntity<Test>("Data Source=MyOracleDB;Integrated Security=yes;", Databases.Oracle); // Or Sql : Databases.Sql
// 1 - select * from Test
List<Test> rows = dc.AllData().Data;
// if error is happend you can know by : dc.AllData().Returened.State = false;
// Error message : dc.AllData().Returened.ErrorMessage
/*=========================================*/
// 2 - SELECT * FROM Test WHERE Name LIKE '%test%'
List<Test> row = dc.Contains(new App.Entities.Models.Func()
{
ColumnName = "Name",
TypeOutParam = App.Entities.Models.DataTypes._string,
Value = "test"
}).Data;
/*=========================================*/
// 3 - Delete from Test where ID = 1
// Id you h've errors you can see it by :
// Deletedrow.Returened.ErrorMessage
// NO Errors : Deletedrow.Returened.State == true
var Deletedrow = dc.Delete(1);
/*=========================================*/
// 4 - Execute Stored Procedure : FindTest this is for SQL
// Sp has parameter : ID
// Full Code Sp :
/*
CREATE PROCEDURE [dbo].[FindTest]
@ID int
AS
BEGIN
SELECT * From Test where ID = @ID
END
*/
var Sp_Row = dc.Select(new App.Entities.Models.StoredProcedure()
{
arr = new System.Collections.ArrayList() { 1 },
Params = new List<string>() { "ID" },
StoredProcedureName = "FindTest"
}).Data;
/*=========================================*/
// 5 - SELECT * From Test where ID = 1
Test rowData = dc.Find(1).SingleData;
/*=========================================*/
// 6 - select top(1) from Test
// dc.LastOrDefault() = select top(1) from test order by ID desc
var FirstOrDefault = dc.FirstOrDefault();
if (FirstOrDefault.SingleData != null)
{
Test record = FirstOrDefault.SingleData;
}
/*=========================================*/
// 7 - select * from Test ==> but Datatable not List<Test>
DataTable dt = dc.GetListDataTable().dataTable;
/*=========================================*/
// 8 - Insert into Test values('test2' , '2016-01-01 11:11:11' , 11);
var rowInserted = dc.Insert(new Test() { Name = "test2", Date = DateTime.Now, Price = 11 });
// For update
var rowID = dc.Find(1).SingleData;
var rowUpdated = dc.Update(rowID);
/*=========================================*/
// 9 - not supported in next version it 'll be supported
// dc.Trigger(new App.Entities.Models.Trigger() { })
// dc.Transaction(new App.Entities.Models.Trans() { })
/*=========================================*/
}