本文整理汇总了C#中IQueryable.Single方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.Single方法的具体用法?C# IQueryable.Single怎么用?C# IQueryable.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryable
的用法示例。
在下文中一共展示了IQueryable.Single方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Construct
public void Construct(IQueryable<XmlElement> Configuration)
{
XmlElement BindingElement = Configuration.Single(element => element.Name == "Binding");
XmlElement ListenElement = Configuration.Single(element => element.Name == "Listening");
var BindIP = Framework.CONFIG.GetValue<IPAddress>(BindingElement.GetAttributeNode("IP"));
var BindPort = Framework.CONFIG.GetValue<int>(BindingElement.GetAttributeNode("Port"));
var ListenBacklog = Framework.CONFIG.GetValue<int>(ListenElement.GetAttributeNode("Backlog"));
// TODO: VALIDATE OBJECTS /\
var EndPoint = new IPEndPoint(BindIP, BindPort);
this.InnerSocket = new Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
this.InnerSocket.Bind(EndPoint);
this.InnerSocket.Blocking = false;
this.InnerSocket.Listen(ListenBacklog);
Framework.LOG.WriteLine("Listening on: {0}", this.InnerSocket.LocalEndPoint);
}
示例2: TestApplicationService
/// <summary>
/// Initializes a new instance of the <see cref="TestApplicationService" /> class.
/// </summary>
public TestApplicationService()
{
applicantInfo = new List<ApplicantInfo>
{
new ApplicantInfo
{
ApplicantInfoID = 1,
UserName = "JohnnyOne"
},
new ApplicantInfo
{
ApplicantInfoID = 2,
UserName = "SallyTwo"
},
new ApplicantInfo
{
ApplicantInfoID = 3,
UserName = "DaveThree"
},
}.AsQueryable();
applications = new List<Application>
{
new Application
{
ApplicationID = 1,
ApplicantInfoID = 1,
ApplicationInformation = applicantInfo.Single(a => a.ApplicantInfoID.Equals(1))
},
new Application
{
ApplicationID = 2,
ApplicantInfoID = 2,
ApplicationInformation = applicantInfo.Single(a => a.ApplicantInfoID.Equals(2))
},
new Application
{
ApplicationID = 3,
ApplicantInfoID = 3,
ApplicationInformation = applicantInfo.Single(a => a.ApplicantInfoID.Equals(3))
}
}.AsQueryable();
// Setup repositories
var applicationRepository = new Mock<GenericDataRepository<Application>>();
applicationRepository.Setup(
x =>
x.GetSingle(It.IsAny<Func<Application, bool>>(), It.IsAny<Expression<Func<Application, object>>[]>()))
.Returns(
(Func<Application, bool> where, Expression<Func<Application, object>>[] nav) =>
applications.Where(where).Single());
applicationRepository.Setup(
x => x.GetList(It.IsAny<Func<Application, bool>>(), It.IsAny<Expression<Func<Application, object>>[]>()))
.Returns(
(Func<Application, bool> where, Expression<Func<Application, object>>[] nav) =>
applications.Where(where).ToList());
applicationRepository.Setup(x => x.Add(It.IsAny<Application[]>()))
.Callback((Application[] aList) =>
{
foreach (Application a in aList)
{
List<Application> new_aList = applications.ToList();
new_aList.Add(a);
applications = new_aList.AsQueryable();
}
});
/* Want to find a way to do this without rebuilding the list
applicationRepository.Setup(x => x.Update(It.IsAny<Application[]>()))
.Callback((Application[] aList) =>
{
foreach (Application a in aList)
{
Application updatedApplication = applications.(x => x.ApplicationID.Equals(a.ApplicationID));
updatedApplication = a;
applications = new_aList.AsQueryable();
}
});
*/
var applicantInfoRepository = new Mock<GenericDataRepository<ApplicantInfo>>();
applicantInfoRepository.Setup(
x =>
x.GetSingle(It.IsAny<Func<ApplicantInfo, bool>>(),
It.IsAny<Expression<Func<ApplicantInfo, object>>[]>()))
.Returns(
(Func<ApplicantInfo, bool> where, Expression<Func<ApplicantInfo, object>>[] nav) =>
applicantInfo.Where(where).Single());
applicantInfoRepository.Setup(
x =>
x.GetList(It.IsAny<Func<ApplicantInfo, bool>>(),
It.IsAny<Expression<Func<ApplicantInfo, object>>[]>()))
.Returns(
//.........这里部分代码省略.........
示例3: TestPositionService
/// <summary>
/// Initializes a new instance of the <see cref="TestPositionService"/> class.
/// </summary>
public TestPositionService()
{
// Initialize
positions = new List<Position>
{
new Position
{
PositionID = 1,
Title = "Title 1",
ShortDescription = "Short Desc 1",
LongDescription = "Long Desc 1",
MinSalary = 1.0f,
MaxSalary = 2.0f
},
new Position
{
PositionID = 2,
Title = "Title 2",
ShortDescription = "Short Desc 2",
LongDescription = "Long Desc 2",
MinSalary = 3.0f,
MaxSalary = 4.0f
},
new Position
{
PositionID = 3,
Title = "Title 3",
ShortDescription = "Short Desc 3",
LongDescription = "Long Desc 3",
MinSalary = 5.0f,
MaxSalary = 6.0f
}
}.AsQueryable();
stores = new List<Store>
{
new Store
{
StoreID = 1,
Region = "Region 1"
},
new Store
{
StoreID = 2,
Region = "Region 1"
},
new Store
{
StoreID = 3,
Region = "Region 2"
}
}.AsQueryable();
contracts = new List<Contract>
{
new Contract
{
ContractID = 1,
StartDate = new DateTime(2014, 03, 1),
EndDate = new DateTime(2014, 03, 25),
FullTime = false,
PositionID = 1,
Position = positions.Single(p => p.PositionID.Equals(1)),
StoreID = 1,
Store = stores.Single(s => s.StoreID.Equals(1))
},
new Contract
{
ContractID = 2,
StartDate = new DateTime(2014, 03, 1),
EndDate = new DateTime(2014, 03, 25),
FullTime = true,
PositionID = 2,
Position = positions.Single(x => x.PositionID.Equals(2)),
StoreID = 2,
Store = stores.Single(s => s.StoreID.Equals(2))
},
new Contract
{
ContractID = 3,
StartDate = new DateTime(2014, 03, 1),
EndDate = new DateTime(2014, 03, 25),
FullTime = false,
PositionID = 3,
Position = positions.Single(x => x.PositionID.Equals(3)),
StoreID = 3,
Store = stores.Single(s => s.StoreID.Equals(3))
}
}.AsQueryable();
// This sets up each method for accepting lambda expressions and maps to the memory
// objects Could probably be done in a more single purpose generic way later.
var contractRepository = new Mock<GenericDataRepository<Contract>>();
contractRepository.Setup(
x => x.GetSingle(It.IsAny<Func<Contract, bool>>(), It.IsAny<Expression<Func<Contract, object>>[]>()))
.Returns(
(Func<Contract, bool> where, Expression<Func<Contract, object>>[] nav) =>
//.........这里部分代码省略.........
示例4: TestQuestionnaireService
/// <summary>
/// Initializes a new instance of the <see cref="TestQuestionnaireService" /> class.
/// </summary>
public TestQuestionnaireService()
{
positions = new List<Position>
{
new Position
{
PositionID = 1,
Title = "Title 1",
ShortDescription = "Short Desc 1",
LongDescription = "Long Desc 1",
MinSalary = 1.0f,
MaxSalary = 2.0f,
},
new Position
{
PositionID = 2,
Title = "Title 2",
ShortDescription = "Short Desc 2",
LongDescription = "Long Desc 2",
MinSalary = 3.0f,
MaxSalary = 4.0f
},
new Position
{
PositionID = 3,
Title = "Title 3",
ShortDescription = "Short Desc 3",
LongDescription = "Long Desc 3",
MinSalary = 5.0f,
MaxSalary = 6.0f
}
}.AsQueryable();
stores = new List<Store>
{
new Store
{
StoreID = 1,
Region = "Region 1"
},
new Store
{
StoreID = 2,
Region = "Region 1"
},
new Store
{
StoreID = 3,
Region = "Region 2"
}
}.AsQueryable();
contracts = new List<Contract>
{
new Contract
{
ContractID = 1,
StartDate = new DateTime(2014, 03, 1),
EndDate = new DateTime(2014, 03, 25),
FullTime = false,
PositionID = 1,
Position = positions.Single(p => p.PositionID.Equals(1)),
StoreID = 1,
Store = stores.Single(s => s.StoreID.Equals(1))
},
new Contract
{
ContractID = 2,
StartDate = new DateTime(2014, 03, 1),
EndDate = new DateTime(2014, 03, 25),
FullTime = true,
PositionID = 2,
Position = positions.Single(x => x.PositionID.Equals(2)),
StoreID = 2,
Store = stores.Single(s => s.StoreID.Equals(2))
},
new Contract
{
ContractID = 3,
StartDate = new DateTime(2014, 03, 1),
EndDate = new DateTime(2014, 03, 25),
FullTime = false,
PositionID = 3,
Position = positions.Single(x => x.PositionID.Equals(3)),
StoreID = 3,
Store = stores.Single(s => s.StoreID.Equals(3))
}
}.AsQueryable();
answers = new List<Answer>
{
new Answer
{
AnswerID = 1,
AnswerText = "",
CorrectAnswer = true
},
//.........这里部分代码省略.........
示例5: AssertSort
private static void AssertSort(IQueryable<ISortOrderedEntity> set, int sortOrder, string name)
{
Assert.AreEqual(name, (set.Single(s => s.SortOrder == sortOrder) as SamepleEntity).Name);
}