本文整理汇总了C#中MongoRepository.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# MongoRepository.FirstOrDefault方法的具体用法?C# MongoRepository.FirstOrDefault怎么用?C# MongoRepository.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoRepository
的用法示例。
在下文中一共展示了MongoRepository.FirstOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
/// <summary>
/// Creates the production system and loads the system configuration.
/// If no configuration exists, a default configuration is loaded.
/// </summary>
private static ProductionSystem Init()
{
JsonSerializerSettings.Converters.Add(new IpAddressConverter());
JsonSerializerSettings.Converters.Add(new IpEndPointConverter());
JsonSerializerSettings.Formatting = Formatting.Indented;
var psrepo = new MongoRepository<ProductionSystem>();
var configuredSystemName = ConfigurationManager.AppSettings["SystemName"];
var configuredSystemNumber = int.Parse(ConfigurationManager.AppSettings["SystemNumber"]);
var loadedDbConfig = psrepo.FirstOrDefault(ps => ps.Name == configuredSystemName && ps.Number == configuredSystemNumber);
if (loadedDbConfig == null)
{
// create dummy config
loadedDbConfig = CreateDefaultSystemConfig();
// create indexes
new MongoRepository<Device>()
.Collection
.CreateIndex(IndexKeys<Device>.Ascending(d => d.ServerId), IndexOptions.SetUnique(true));
new MongoRepository<Order>()
.Collection
.CreateIndex(IndexKeys<Order>.Ascending(d => d.OrderNo), IndexOptions.SetUnique(true));
new MongoRepository<ParameterSet>()
.Collection
.CreateIndex(IndexKeys<ParameterSet>.Ascending(d => d.Name), IndexOptions.SetUnique(true));
foreach (var station in loadedDbConfig.Stations)
{
station.Status = StationStatus.Idle;
}
}
return loadedDbConfig;
}
示例2: LoadOrCreateDummy
public static ParameterSet LoadOrCreateDummy()
{
var repo = new MongoRepository<ParameterSet>();
var defaultName = "DEFAULT";
var ps = repo.FirstOrDefault(p => p.Name == defaultName);
if (ps != null)
{
repo.Delete(ps);
}
ps = new ParameterSet
{
Name = defaultName,
Parameters = new List<Parameter>
{
new Parameter()
{
Name = "Server-ID",
TagId = ParameterTagId.ServerId,
IsActive = true,
IsAutoIncrement = true,
IsWriteOnly = false,
IsPartOfMatrixCode = true,
TargetValue = "0A-01-44-5A-47-01-02-62-5A-17",
ObisCode = RegisterIds.DeviceId.ToHexString("-")
},
new Parameter()
{
Name = "Hersteller Seriennummer",
TagId = ParameterTagId.ManufacturerSerialNumber,
IsActive = true,
IsAutoIncrement = false,
TargetValue = "", // derived from serverId
ObisCode = VendorSpecificRegisterIds.ManufacturerSerialNumber.ToHexString("-")
},
new Parameter()
{
Name = "Reallin Barcode",
TagId = ParameterTagId.PcbBarCode,
ObisCode = "",
IsNameplateOnly = true,
TargetValue = ""
},
new Parameter()
{
Name = "Messbetriebsart",
TagId = ParameterTagId.MeasurementMode,
IsActive = true,
TargetValue = "MM2",
ObisCode = VendorSpecificRegisterIds.MeasurementMode.ToHexString("-")
},
new Parameter()
{
Name="ECC Schlüssel generieren",
TagId = ParameterTagId.GenerateKeys,
IsActive = true,
TargetValue = "True",
ObisCode = VendorSpecificRegisterIds.GenerateKeys.ToHexString("-"),
IsWriteOnly = true
},
new Parameter()
{
Name = "ECC Public Key",
TagId = ParameterTagId.PublicKey,
IsActive = true,
IsReadOnly = true,
IsPartOfMatrixCode = true,
TargetValue = "",
ObisCode = RegisterIds.PublicKeySignature.ToHexString("-")
},
new Parameter()
{
Name = "Initialer AES Key M",
TagId = ParameterTagId.InitialKeyM,
IsActive = true,
IsRandomTargetValue = true,
TargetValue = "",
ObisCode = RegisterIds.SymmetricInitialKey.ToHexString("-")
},
new Parameter()
{
Name = "Grid Option",
TagId = ParameterTagId.GridOption,
IsActive = true,
TargetValue = "True",
ObisCode = RegisterIds.GridOptionEnabled.ToHexString("-")
},
new Parameter()
{
Name = "Tariff Option",
TagId = ParameterTagId.TarifOptionActive,
IsActive = true,
TargetValue = "True",
ObisCode = RegisterIds.TariffOptionEnabled.ToHexString("-")
},
new Parameter()
{
Name = "Tariff Configuration",
TagId = ParameterTagId.InverseTariffControl,
ObisCode = ObisEdl.DzgTerminalControlReverse.ToHexString("-"),
//.........这里部分代码省略.........