本文整理汇总了C#中System.Db类的典型用法代码示例。如果您正苦于以下问题:C# Db类的具体用法?C# Db怎么用?C# Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Db类属于System命名空间,在下文中一共展示了Db类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Relations_Zero_One_And_One_One_Async
public async Task Relations_Zero_One_And_One_One_Async()
{
var db = new Db();
db.Initialize(TestConstants.SqlClientConnectionString, "System.Data.SqlClient");
var result = await db.CreateCommand("select * from [dbo].[BaseTable] where [email protected]")
.AddParameter("@id", 5)
.ReadOneMapToAsync<BaseTable>();
// zero one
if (result.ZeroOneId.HasValue)
{
var zeroOne = await db.CreateCommand("Select * from [dbo].[ZeroOne] where [email protected]")
.AddParameter("@id", result.ZeroOneId)
.ReadOneMapToAsync<ZeroOne>();
result.ZeroOne = zeroOne;
}
// one one
var oneOne = await db.CreateCommand("Select * from [dbo].[OneOne] where [email protected]")
.AddParameter("@id", result.OneOneId)
.ReadOneMapToAsync<OneOne>();
result.OneOne = oneOne;
Assert.AreEqual(result.Name.TrimEnd(), "Base 2");
Assert.IsTrue(result.ZeroOneId.HasValue && result.ZeroOneId == 1);
Assert.AreEqual(result.ZeroOne.Id, 1);
Assert.AreEqual(result.ZeroOne.Name, "Zero 1");
Assert.AreEqual(result.OneOneId, 3);
Assert.AreEqual(result.OneOne.Id, 3);
Assert.AreEqual(result.OneOne.Name, "One 2");
}
示例2: Relations_Zero_One_And_One_One
public void Relations_Zero_One_And_One_One()
{
var db = new Db();
db.Initialize(TestConstants.SqlClientConnectionString, "System.Data.SqlClient");
var result = db.CreateCommand("select * from [dbo].[BaseTable] where [email protected]")
.AddParameter("@id", 4)
.ReadOneMapTo<BaseTable>();
// zero one
if (result.ZeroOneId.HasValue)
{
var zeroOne = db.CreateCommand("Select * from [dbo].[ZeroOne] where [email protected]")
.AddParameter("@id", result.ZeroOneId)
.ReadOneMapTo<ZeroOne>();
result.ZeroOne = zeroOne;
}
// one one
var oneOne = db.CreateCommand("Select * from [dbo].[OneOne] where [email protected]")
.AddParameter("@id", result.OneOneId)
.ReadOneMapTo<OneOne>();
result.OneOne = oneOne;
Assert.AreEqual(result.Name.TrimEnd(), "Base 1");
Assert.IsFalse(result.ZeroOneId.HasValue);
Assert.AreEqual(result.OneOneId,2);
Assert.AreEqual(result.OneOne.Id, 2);
Assert.AreEqual(result.OneOne.Name, "One 1");
}
示例3: Merge
public static void Merge(string path, Db to_db)
{
Log.Warning ("Will merge db {0} into main f-spot db {1}", path, FSpot.Global.BaseDirectory + "/photos.db" );
Db from_db = new Db ();
from_db.Init (path, true);
//MergeDb mdb = new MergeDb (from_db, to_db);
}
示例4: getHtmlAsync
/// <summary>
/// Get html Async
/// </summary>
private string getHtmlAsync(string url, string customUserAgent, Db.HttpHeadersInfoCollection httpHeaders)
{
try
{
//set new proxy if use proxy
CookieAwareWebClient client = Factory.Instance.getWebClientNext(customUserAgent,httpHeaders);
client = setCredential(client, url);
//Set Wait time
System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitEachRequestMilliseconds);
//Stream s =
asyncEnd = false;
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(new Uri(url));
while (asyncEnd == false)
System.Threading.Thread.Sleep(10);
return this.currentHtml;
}
catch (Exception ex)
{
//Wait after error - prevent next request
System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitAfterError);
Factory.Instance.log.Error(ex);
return string.Empty;
}
}
示例5: Send
public static async Task Send(Db db)
{
var host = HttpContext.Current?.Request.ServerVariables["HTTP_HOST"];
if (host == null || !host.Equals("jeegoordah.azurewebsites.net", StringComparison.InvariantCultureIgnoreCase))
{
throw new Exception($"Sending notifications is disabled for {host}");
}
var sendTasks = db.Query<Bro>()
.Where(x => x.Email != null)
.Where(x => x.Notifications.Count > 0)
.ToArray()
.Select(async bro =>
{
var message = new SendGridMessage
{
From = _from,
To = new[] {new MailAddress(bro.Email)},
Subject = "Jeegoordah notifications",
Text = GetContent(bro.Notifications),
Html = null,
};
_logger.I($"Sending {bro.Notifications.Count} notifications for {bro.Name}");
await _transport.DeliverAsync(message);
_logger.I($"Notifications for {bro.Name} sent");
});
await Task.WhenAll(sendTasks);
db.Query<Notification>().ForEach(db.Session.Delete);
_logger.I("Notifications deleted");
}
示例6: ShouldPropagateFieldsFromAllBaseTemplates
public void ShouldPropagateFieldsFromAllBaseTemplates()
{
// arrange
ID myTemplateId = ID.NewID;
using (var db = new Db
{
this.baseTemplateOne,
this.baseTemplateTwo,
this.baseTemplateThree,
new DbTemplate("Main Template", myTemplateId) {BaseIDs = new[] {this.baseTemplateOne.ID, this.baseTemplateThree.ID}},
new DbItem("home", ID.NewID, myTemplateId)
})
{
// act
Item home = db.GetItem("/sitecore/content/home");
Template template = TemplateManager.GetTemplate(myTemplateId, db.Database);
// assert
// note: as noted above, fields propagation should "just" work
home.Fields["Title"].Should().NotBeNull("home.Fields[\"Title\"]");
home.Fields["Description"].Should().NotBeNull("home.Fields[\"Description\"]");
template.GetField("Title").Should().NotBeNull("template.GetField(\"Title\")");
template.GetField("Description").Should().NotBeNull("template.GetField(\"Description\")");
}
}
示例7: CameraFileSelectionDialog
public CameraFileSelectionDialog (GPhotoCamera cam, Db datab)
{
camera = cam;
db = datab;
saved_files = null;
selected_tags = null;
}
示例8: HistoryPresenter
public HistoryPresenter(Db db)
{
this.db = db;
nullAccount = new Account();
nullAccount.Name = "";
}
示例9: Save
public async Task<int> Save(long routeId, Station station, int number)
{
if(routeId <= 0) throw new ArgumentException("routeId <= 0");
if(station == null) throw new ArgumentNullException("station");
using (var db = new Db())
{
using (var transaction = db.Database.BeginTransaction(IsolationLevel.RepeatableRead))
{
try
{
var route = db.Routes.SingleOrDefault(s => s.Id == routeId);
if(route == null) throw new NullReferenceException("route");
station = await _stationRepository.GetByLatLng(station.Latitude, station.Longitude);
if(station == null) throw new NullReferenceException("station");
var routeStation = new RouteStation(){Number = number,RouteId = routeId,StationId = station.Id};
db.Entry(routeStation).State = EntityState.Added;
return await db.SaveChangesAsync();
}
catch (Exception ex)
{
transaction.Rollback();
Log.Error(ex.Message);
throw;
}
}
}
}
示例10: getHtml
/// <summary>
/// Get html
/// </summary
private static string getHtml(string url, string customUserAgent, Db.HttpHeadersInfoCollection httpHeaders)
{
try
{
//set new proxy if use proxy
CookieAwareWebClient client = Factory.Instance.getWebClientNext(customUserAgent,httpHeaders);
client = setCredential(client, url);
//Set Wait time
System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitEachRequestMilliseconds);
Stream s = client.OpenRead(url); ;
StreamReader sr = new StreamReader(s);
string html = sr.ReadToEnd();
s.Close();
return html;
}
catch (Exception ex)
{
//Wait after error - prevent next request
System.Threading.Thread.Sleep(Factory.Instance.i.Project.ScrapingSetting.waitAfterError);
Factory.Instance.log.Error(ex);
return string.Empty;
}
}
示例11: Run
public void Run()
{
_Console.WriteLine("End statement with ';'");
_Console.WriteLine("Enter 'quit' when done");
_Console.WriteLine();
string line;
string statement = "";
_Console.Write(">");
while((line = _Console.ReadLine()) != "quit") {
statement += line + '\n';
if(!line.Trim().EndsWith(";"))
continue;
using(var db = new Db()) {
try {
db.ExecuteReader(statement, PrintHeader,PrintGrid);
} catch(Exception e) {
_Console.WriteLine(e.Message);
}
}
statement = "";
_Console.Write(">");
}
}
示例12: HttpDataHandler
public HttpDataHandler(HttpRequest request, Db db)
{
string cmd = request.Form["ex"];
Form = request.Form;
Database = db;
Nodes = new Node();
if (!string.IsNullOrEmpty(cmd))
{
if (cmd.Equals("insert"))
{
ParseInsertQuery();
}
else if (cmd.Equals("update"))
{
ParseUpdateQuery();
}
else if (cmd.Equals("delete"))
{
ParseDeleteQuery();
}
else if (cmd.Equals("select"))
{
ParseSelectQuery();
}
}
}
示例13: ShouldBeThreadLocalStandardValuesProvider
public void ShouldBeThreadLocalStandardValuesProvider()
{
var templateId = ID.NewID;
var itemId = ID.NewID;
var fieldId = ID.NewID;
var t1 = Task.Factory.StartNew(() =>
{
using (var db = new Db
{
new DbTemplate(templateId) { { fieldId, "$name" } },
new DbItem("Home", itemId, templateId)
})
{
Thread.Sleep(1000);
db.GetItem(itemId)[fieldId].Should().Be("Home");
}
});
var t2 = Task.Factory.StartNew(() =>
{
using (var db = new Db
{
new DbTemplate(templateId) { fieldId },
new DbItem("Home", itemId, templateId)
})
{
db.GetItem(itemId)[fieldId].Should().BeEmpty();
}
});
t1.Wait();
t2.Wait();
}
示例14: FieldBase
public FieldBase(Db.Field Field)
{
this.TenantID = Configure.GetTenantResolutionProvider().GetTenantID();
if (this.TenantID != Field.TenantID)
{
Log.Fatal("TenantID Does not match. FieldID: {0}, Global TenantID: {1}, Field TenantID: {2}",
Field.FieldID, this.TenantID, Field.TenantID);
throw new FatalException("Data error.");
}
this.Dirty = false;
this.FieldID = Field.FieldID;
this.ValueString = Field.ValueText;
this.ValueDate = Field.ValueDate;
this.ValueDecimal = Field.ValueDecimal;
this.ValueBool = Field.ValueBoolean;
this.ValueLookup = Field.ValueLookup;
this.ValueBinary = Field.ValueBinary;
this.ValueEntityReference = Field.ValueEntityReference;
this.ValueItemReference = Field.ValueItemReference;
this.Guid = Field.Guid;
RefreshOriginalValues();
}
示例15: ShouldPropagateFieldsFromTheBaseTemplate
public void ShouldPropagateFieldsFromTheBaseTemplate()
{
// arrange
ID templateId = ID.NewID;
using (var db = new Db
{
this.baseTemplateOne,
new DbTemplate("My Template", templateId) {BaseIDs = new[] {this.baseTemplateOne.ID}},
new DbItem("home", ID.NewID, templateId)
})
{
// act
Item home = db.GetItem("/sitecore/content/home");
Template template = TemplateManager.GetTemplate(templateId, db.Database);
Template baseTemplate = TemplateManager.GetTemplate(this.baseTemplateOne.ID, db.Database);
TemplateField titleField = baseTemplate.GetField("Title");
// assert
// note: it should "just" work as Sitecore wil do all the looking up the templates chain
template.GetFields(false).Should().NotContain(f => f.Name == "Title" || f.ID == titleField.ID);
template.GetFields(true).Should().Contain(f => f.Name == "Title" && f.ID == titleField.ID);
template.GetField("Title").Should().NotBeNull("template.GetField(\"Title\")");
template.GetField(titleField.ID).Should().NotBeNull("template.GetField(titleField.ID)");
home.Fields["Title"].Should().NotBeNull("home.Fields[\"Title\"]");
home.Fields[titleField.ID].Should().NotBeNull("home.Fields[titleField.ID]");
}
}