本文整理汇总了C#中OrmLiteConnectionFactory.Scalar方法的典型用法代码示例。如果您正苦于以下问题:C# OrmLiteConnectionFactory.Scalar方法的具体用法?C# OrmLiteConnectionFactory.Scalar怎么用?C# OrmLiteConnectionFactory.Scalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrmLiteConnectionFactory
的用法示例。
在下文中一共展示了OrmLiteConnectionFactory.Scalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_get_scalar_value
public void Can_get_scalar_value(){
List<Author> authors = new List<Author>();
authors.Add(new Author() { Name = "Demis Bellot", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 99.9m, Comments = "CSharp books", Rate = 10, City = "London", FloatProperty=10.25f, DoubleProperty=3.23 });
authors.Add(new Author() { Name = "Angel Colmenares", Birthday = DateTime.Today.AddYears(-25), Active = true, Earnings = 50.0m, Comments = "CSharp books", Rate = 5, City = "Bogota",FloatProperty=7.59f,DoubleProperty=4.23 });
authors.Add(new Author() { Name = "Adam Witco", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 80.0m, Comments = "Math Books", Rate = 9, City = "London",FloatProperty=15.5f,DoubleProperty=5.42 });
authors.Add(new Author() { Name = "Claudia Espinel", Birthday = DateTime.Today.AddYears(-23), Active = true, Earnings = 60.0m, Comments = "Cooking books", Rate = 10, City = "Bogota",FloatProperty=0.57f, DoubleProperty=8.76});
authors.Add(new Author() { Name = "Libardo Pajaro", Birthday = DateTime.Today.AddYears(-25), Active = true, Earnings = 80.0m, Comments = "CSharp books", Rate = 9, City = "Bogota", FloatProperty=8.43f, DoubleProperty=7.35});
authors.Add(new Author() { Name = "Jorge Garzon", Birthday = DateTime.Today.AddYears(-28), Active = true, Earnings = 70.0m, Comments = "CSharp books", Rate = 9, City = "Bogota", FloatProperty=1.25f, DoubleProperty=0.3652});
authors.Add(new Author() { Name = "Alejandro Isaza", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 70.0m, Comments = "Java books", Rate = 0, City = "Bogota", FloatProperty=1.5f, DoubleProperty=100.563});
authors.Add(new Author() { Name = "Wilmer Agamez", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 30.0m, Comments = "Java books", Rate = 0, City = "Cartagena", FloatProperty=3.5f,DoubleProperty=7.23 });
authors.Add(new Author() { Name = "Rodger Contreras", Birthday = DateTime.Today.AddYears(-25), Active = true, Earnings = 90.0m, Comments = "CSharp books", Rate = 8, City = "Cartagena", FloatProperty=0.25f,DoubleProperty=9.23 });
authors.Add(new Author() { Name = "Chuck Benedict", Birthday = DateTime.Today.AddYears(-22), Active = true, Earnings = 85.5m, Comments = "CSharp books", Rate = 8, City = "London", FloatProperty=9.95f,DoubleProperty=4.91 });
authors.Add(new Author() { Name = "James Benedict II", Birthday = DateTime.Today.AddYears(-22), Active = true, Earnings = 85.5m, Comments = "Java books", Rate = 5, City = "Berlin",FloatProperty=4.44f,DoubleProperty=6.41 });
authors.Add(new Author() { Name = "Ethan Brown", Birthday = DateTime.Today.AddYears(-20), Active = true, Earnings = 45.0m, Comments = "CSharp books", Rate = 5, City = "Madrid", FloatProperty=6.67f, DoubleProperty=8.05 });
authors.Add(new Author() { Name = "Xavi Garzon", Birthday = DateTime.Today.AddYears(-22), Active = true, Earnings = 75.0m, Comments = "CSharp books", Rate = 9, City = "Madrid", FloatProperty=1.25f, DoubleProperty=3.99});
authors.Add(new Author() { Name = "Luis garzon", Birthday = DateTime.Today.AddYears(-22), Active = true, Earnings = 85.0m, Comments = "CSharp books", Rate = 10,
City = "Mexico",
LastActivity= DateTime.Today,
NRate=5,
FloatProperty=1.25f,
NFloatProperty=3.15f,
DoubleProperty= 1.25,
NDoubleProperty= 8.25
});
using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
{
db.CreateTable<Author>(true);
db.DeleteAll<Author>();
db.InsertAll(authors);
var expectedDate = authors.Max(e=>e.Birthday);
var r1 = db.Scalar<Author, DateTime>( e => Sql.Max(e.Birthday) );
Assert.That(expectedDate, Is.EqualTo(r1));
expectedDate = authors.Where(e=>e.City=="London").Max(e=>e.Birthday);
r1 = db.Scalar<Author, DateTime>( e => Sql.Max(e.Birthday), e=>e.City=="London" );
Assert.That(expectedDate, Is.EqualTo(r1));
r1 = db.Scalar<Author, DateTime>( e => Sql.Max(e.Birthday), e=>e.City=="SinCity" );
Assert.That( default(DateTime), Is.EqualTo(r1));
var expectedNullableDate= authors.Max(e=>e.LastActivity);
DateTime? r2 = db.Scalar<Author,DateTime?>(e=> Sql.Max(e.LastActivity));
Assert.That(expectedNullableDate, Is.EqualTo(r2));
expectedNullableDate= authors.Where(e=> e.City=="Bogota").Max(e=>e.LastActivity);
r2 = db.Scalar<Author,DateTime?>(
e=> Sql.Max(e.LastActivity),
e=> e.City=="Bogota" );
Assert.That(expectedNullableDate, Is.EqualTo(r2));
r2 = db.Scalar<Author, DateTime?>( e => Sql.Max(e.LastActivity), e=>e.City=="SinCity" );
Assert.That( default(DateTime?), Is.EqualTo(r2));
var expectedDecimal= authors.Max(e=>e.Earnings);
decimal r3 = db.Scalar<Author,decimal>(e=> Sql.Max(e.Earnings));
Assert.That(expectedDecimal, Is.EqualTo(r3));
expectedDecimal= authors.Where(e=>e.City=="London").Max(e=>e.Earnings);
r3 = db.Scalar<Author,decimal>(e=> Sql.Max(e.Earnings), e=>e.City=="London");
Assert.That(expectedDecimal, Is.EqualTo(r3));
r3 = db.Scalar<Author,decimal>(e=> Sql.Max(e.Earnings), e=>e.City=="SinCity");
Assert.That( default(decimal), Is.EqualTo(r3));
var expectedNullableDecimal= authors.Max(e=>e.NEarnings);
decimal? r4 = db.Scalar<Author,decimal?>(e=> Sql.Max(e.NEarnings));
Assert.That(expectedNullableDecimal, Is.EqualTo(r4));
expectedNullableDecimal= authors.Where(e=>e.City=="London").Max(e=>e.NEarnings);
r4 = db.Scalar<Author,decimal?>(e=> Sql.Max(e.NEarnings), e=>e.City=="London");
Assert.That(expectedNullableDecimal, Is.EqualTo(r4));
r4 = db.Scalar<Author,decimal?>(e=> Sql.Max(e.NEarnings), e=>e.City=="SinCity");
Assert.That( default(decimal?), Is.EqualTo(r4));
var expectedDouble =authors.Max(e=>e.DoubleProperty);
double r5 = db.Scalar<Author,double>(e=> Sql.Max(e.DoubleProperty));
Assert.That(expectedDouble, Is.EqualTo(r5));
expectedDouble =authors.Where(e=>e.City=="London").Max(e=>e.DoubleProperty);
r5 = db.Scalar<Author,double>(e=> Sql.Max(e.DoubleProperty), e=>e.City=="London");
Assert.That(expectedDouble, Is.EqualTo(r5));
r5 = db.Scalar<Author,double>(e=> Sql.Max(e.DoubleProperty), e=>e.City=="SinCity");
Assert.That(default(double),Is.EqualTo(r5));
var expectedNullableDouble =authors.Max(e=>e.NDoubleProperty);
double? r6 = db.Scalar<Author,double?>(e=> Sql.Max(e.NDoubleProperty));
Assert.That(expectedNullableDouble, Is.EqualTo(r6));
//.........这里部分代码省略.........
示例2: Can_select_scalar_value
public void Can_select_scalar_value()
{
const int n = 5;
using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
{
db.CreateTable<ModelWithIdAndName>(true);
db.DeleteAll<ModelWithIdAndName>();
n.Times(x => db.Insert(ModelWithIdAndName.Create(0)));
var count = db.Scalar<int>("SELECT COUNT(*) FROM ModelWIN");
Assert.That(count, Is.EqualTo(n));
}
}