本文整理汇总了C#中List.AsQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# List.AsQueryable方法的具体用法?C# List.AsQueryable怎么用?C# List.AsQueryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.AsQueryable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllProducts
public IEnumerable<Product> GetAllProducts()
{
string sqlExecute = string.Empty;
List<Product> ProductList = new List<Product>();
try
{
#region SQL 語法
sqlExecute = @"select * from Product ";
#endregion SQL 語法
#region SQL 執行
using (var conn = SQLFunc.OpenConnection(DBList.Test))
{
ProductList= conn.Query<Product>(sqlExecute).ToList();
}
var builder = new ODataConventionModelBuilder() { Namespace = "Default" };
builder.EntitySet<Product>("Products");
var model = builder.GetEdmModel();
return ProductList.AsQueryable();
#endregion
}
catch (Exception ex)
{
}
return ProductList.AsQueryable();
}
示例2: Create
public static IRepository<WorkLog> Create()
{
var logsList = new List<WorkLog>();
for (int i = 1; i < 20; i++)
{
logsList.Add(new WorkLog
{
Id = i,
ShortDescription = "Log short Description " + i,
StartTime = DateTime.Now
});
}
logsList.Add(new WorkLog
{
Id = 25,
ShortDescription = "Log short Description " + 25,
StartTime = DateTime.Now,
EndTime = DateTime.Now.AddHours(2)
});
var repo = new Mock<IRepository<WorkLog>>();
repo.Setup(x => x.All()).Returns(logsList.AsQueryable());
repo.Setup(x => x.Find(It.IsAny<Expression<Func<WorkLog, bool>>>()))
.Returns<Expression<Func<WorkLog, bool>>>(id => logsList.AsQueryable().Where(id));
repo.Setup(x => x.Update(It.IsAny<WorkLog>())).Verifiable();
return repo.Object;
}
示例3: GetPostsService
public static IPostsService GetPostsService()
{
var post = new Post
{
Content = "test post",
Id = 1,
PostDate = new DateTime(2015, 11, 1),
ThreadId = 1,
UserId = "id1",
User = new User { Nickname = "testuser" },
Thread = new Thread { Title = "testTitle" },
Comments = new List<Comment>(),
Votes = new List<Vote>()
};
var posts = new List<Post>()
{
post
};
var postsService = new Mock<IPostsService>();
postsService.Setup(p => p.Add(It.IsAny<string>(), It.Is<int>(t => t > 100), It.IsAny<string>())).Throws<ArgumentException>();
postsService.Setup(p => p.Add(It.IsAny<string>(), It.Is<int>(t => t < 100), It.IsAny<string>())).Returns(1);
postsService.Setup(p => p.GetById(It.IsAny<int>())).Returns(post);
postsService.Setup(p => p.GetByThread(It.IsAny<int>())).Returns(posts.AsQueryable());
postsService.Setup(p => p.GetByUser(It.Is<string>(s => s != "not exist"))).Returns(posts.AsQueryable());
postsService.Setup(p => p.GetByUser(It.Is<string>(s => s == "not exist"))).Throws<ArgumentException>();
postsService.Setup(p => p.Update(It.IsAny<int>(), It.IsAny<string>())).Verifiable();
return postsService.Object;
}
示例4: Waypoints
public async Task<IHttpActionResult> Waypoints(int id)
{
Mission mission = await db.Missions.FindAsync(id);
if (mission == null)
{
return BadRequest();
}
var wps = mission.Waypoints;
List<Waypoint> wpsInOrder = new List<Waypoint>();
if (wps.Count == 0)
{
return Ok(wpsInOrder.AsQueryable());
}
var activeWps = from wp in mission.Waypoints
where wp.IsActive
select wp;
var tail = activeWps.First(wp => wp.NextWaypoint == null && wp.IsActive);
wpsInOrder.Add(tail);
foreach (var wp in activeWps)
{
if (wp.Id == tail.Id)
{
//This is already in the list we don't want to insert it.
continue;
}
var next = wp.NextWaypoint;
int index = next != null ? wpsInOrder.FindIndex(n => n.Id == next.Id) : -1;
if (index == -1)
{
//The next waypoint of this waypoint is not in this list, just insert it behind the last waypoint.
int len = wpsInOrder.Count;
wpsInOrder.Insert(len - 1, wp);
}
else
{
//Insert the waypoint behind its next waypoint.
wpsInOrder.Insert(index, wp);
}
}
var diffType = from wp in wpsInOrder.AsQueryable()
select new
{
MissionId = wp.MissionId,
NextWaypointId = wp.NextWaypointId,
Latitude = wp.Latitude,
Longitude = wp.Longitude,
Altitude = wp.Altitude,
IsActive = wp.IsActive,
Id = wp.Id,
TimeCompleted = wp.TimeCompleted,
WaypointName = wp.WaypointName,
Action = wp.Action,
GeneratedBy = wp.GeneratedBy,
};
return Ok(diffType);
}
示例5: BuildKeyList
public static List<Key> BuildKeyList(List<String[]> ParsedPrefix, List<String[]> ParsedSuffix, List<Family> FamilyList)
{
List<Key> ret = new List<Key>();
foreach(String[] thisKeyPrefix in ParsedPrefix)
{
if (thisKeyPrefix.Length != 2)
throw new Exception();
foreach(String[] thisKeySuffix in ParsedSuffix)
{
if (thisKeySuffix.Length < 2 || thisKeySuffix.Length > 3)
throw new Exception();
Family Family2 = null;
if (thisKeySuffix.Length == 3)
Family2 = FamilyList.AsQueryable().Where(x => x.Name == thisKeySuffix[2]).First();
ret.Add
(
new Key
(
String.Format("{0}{1}", thisKeyPrefix[0], thisKeySuffix[0]),
Int32.Parse(thisKeyPrefix[1]),
FamilyList.AsQueryable().Where(x => x.Name == thisKeySuffix[1]).First(),
Family2
)
);
}
}
return ret;
}
示例6: GetAllCoursesForUser
public IQueryable<Course> GetAllCoursesForUser(string id)
{
var specialty = this.specialtiesRepository
.All()
.Where(s => s.Students.Any(std => std.Id == id))
.Include(s => s.Semesters)
.FirstOrDefault();
var courses = new List<Course>();
if (specialty == null)
{
return courses.AsQueryable();
}
foreach (var item in specialty.Semesters)
{
foreach (var e in item.Courses)
{
courses.Add(e);
}
}
return courses.AsQueryable();
}
示例7: BuildBreedList
public static List<Breed> BuildBreedList(List<String[]> ParsedCSV, List<Monster> MonsterList, List<Family> FamilyList)
{
List<Breed> ret = new List<Breed>();
foreach(String[] thisBreed in ParsedCSV)
{
if (thisBreed.Length < 3 || thisBreed.Length > 4)
throw new Exception();
//check if there is a required depth (+x) for this breed to succeed
int? thisRequiredDepth = null;
if (thisBreed.Length == 4)
thisRequiredDepth = Int32.Parse(thisBreed[3]);
IBreedable thisParent1;
//create first parent (either family or monster)
if(thisBreed[1].StartsWith("*") && thisBreed[1].EndsWith("*"))
{
//this parent is any member of the specified family
thisParent1 = FamilyList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[1].TrimStart('*').TrimEnd('*')).First();
}
else
{
thisParent1 = MonsterList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[1].ToUpper()).First();
}
IBreedable thisParent2;
//create second parent (either family or monster)
if(thisBreed[2].StartsWith("*") && thisBreed[2].EndsWith("*"))
{
//this parent is any member of the specified family
thisParent2 = FamilyList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[2].TrimStart('*').TrimEnd('*')).First();
}
else
{
thisParent2 = MonsterList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[2].ToUpper()).First();
}
ret.Add
(
new Breed
(
MonsterList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[0]).First(),
thisParent1,
thisParent2,
thisRequiredDepth
)
);
}
return ret;
}
示例8: GenericSorter
protected static List<BaseComparer> GenericSorter (List<BaseComparer> list)
{
BaseComparer bc = list[0];
SortColumn scc = bc.ColumnCollection[0] as SortColumn;
ListSortDirection sd = scc.SortDirection;
List<BaseComparer> lbc = null;
if (sd == ListSortDirection.Ascending) {
lbc = list.AsQueryable().AscendingOrder().ToList();
} else {
lbc = list.AsQueryable().DescendingOrder().ToList();
}
return lbc;
}
示例9: LoadParts
private IQueryable<ComposablePartDefinition> LoadParts()
{
if (!Directory.Exists(_dir))
{
return (new ComposablePartDefinition[0]).AsQueryable();
}
var parts = new List<ComposablePartDefinition>();
foreach(var file in Directory.GetFiles(this._dir, "*.dll"))
{
try
{
var assembly = Assembly.LoadFrom(file);
using(var catalog = new AssemblyDiscoveryCatalog(assembly))
{
parts.AddRange(catalog.Parts);
}
}
catch (Exception)
{
// TODO: we should log or trace
}
}
return parts.AsQueryable();
}
示例10: Configure
public virtual void Configure(IEngine engine, ContainerManager containerManager, EventBroker broker, SmartStoreConfig configuration)
{
//other dependencies
containerManager.AddComponentInstance<SmartStoreConfig>(configuration, "sm.configuration");
containerManager.AddComponentInstance<IEngine>(engine, "sm.engine");
containerManager.AddComponentInstance<ContainerConfigurer>(this, "sm.containerConfigurer");
//type finder
containerManager.AddComponent<ITypeFinder, WebAppTypeFinder>("sm.typeFinder");
//register dependencies provided by other assemblies
var typeFinder = containerManager.Resolve<ITypeFinder>();
containerManager.UpdateContainer(x =>
{
var drTypes = typeFinder.FindClassesOfType<IDependencyRegistrar>();
var drInstances = new List<IDependencyRegistrar>();
foreach (var drType in drTypes)
drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType));
//sort
drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
foreach (var dependencyRegistrar in drInstances)
dependencyRegistrar.Register(x, typeFinder);
});
// event broker
containerManager.AddComponentInstance(broker);
// AutofacDependencyResolver
var scopeProvider = new AutofacLifetimeScopeProvider(containerManager.Container);
var dependencyResolver = new AutofacDependencyResolver(containerManager.Container, scopeProvider);
DependencyResolver.SetResolver(dependencyResolver);
}
示例11: FakeCeremony
/// <summary>
/// Fakes the ceremony.
/// </summary>
/// <param name="count">The count.</param>
/// <param name="ceremonyRepository">The ceremony repository.</param>
/// <param name="specificCeremonies">The specific ceremonies.</param>
public static void FakeCeremony(int count, IRepository<Ceremony> ceremonyRepository, List<Ceremony> specificCeremonies)
{
var ceremonies = new List<Ceremony>();
var specificTransactionsCount = 0;
if (specificCeremonies != null)
{
specificTransactionsCount = specificCeremonies.Count;
for (int i = 0; i < specificTransactionsCount; i++)
{
ceremonies.Add(specificCeremonies[i]);
}
}
for (int i = 0; i < count; i++)
{
ceremonies.Add(CreateValidEntities.Ceremony(i + specificTransactionsCount + 1));
}
var totalCount = ceremonies.Count;
for (int i = 0; i < totalCount; i++)
{
ceremonies[i].SetIdTo(i + 1);
int i1 = i;
ceremonyRepository
.Expect(a => a.GetNullableById(i1 + 1))
.Return(ceremonies[i])
.Repeat
.Any();
}
ceremonyRepository.Expect(a => a.GetNullableById(totalCount + 1)).Return(null).Repeat.Any();
ceremonyRepository.Expect(a => a.Queryable).Return(ceremonies.AsQueryable()).Repeat.Any();
ceremonyRepository.Expect(a => a.GetAll()).Return(ceremonies).Repeat.Any();
}
示例12: EmptyDataSource
public JsonResult EmptyDataSource()
{
var people = new List<Person>();
people.Add(new Person { LastName = "Alone", FirstName = "All" });
var dataSource = KendoUiHelper.ParseGridData<Person>(people.AsQueryable());
return Json(dataSource, JsonRequestBehavior.AllowGet);
}
示例13: getSampleCallerTypes
public static IQueryable<RequestorType> getSampleCallerTypes()
{
var requestor0 = new RequestorType {
RequestorTypeID = 0,
Code = "ADMIN",
Value = "Administrator",
Active = true
};
var requestor1 = new RequestorType {
RequestorTypeID = 1,
Code = "DRUG CO",
Value = "Drug Company",
Active = false
};
var requestor2 = new RequestorType {
RequestorTypeID = 2,
Code = "FAMILY",
Value = "Family Members",
Active = false
};
var sampleCallers = new List<RequestorType> {
requestor0,
requestor1,
requestor2
};
return sampleCallers.AsQueryable();
}
示例14: FindTypes
public static IEnumerable<Type> FindTypes(TypeIncludes flags, Type baseType)
{
if (baseType == null) throw new ArgumentNullException("baseType", "Must be set to a type");
Func<Type, bool> predicate = BuildPredicate(flags);
var foundTypes = from containedType in FindTypes(baseType)
where predicate(containedType)
select containedType;
if (!(IsSet(flags, TypeIncludes.ConcreteTypes) && IsConcreteType(baseType)))
{
if(foundTypes.Contains(baseType))
{
IList<Type> b = new List<Type>();
b.Add(baseType);
foundTypes = foundTypes.Except(b.AsQueryable());
}
}
if (IsSet(flags, TypeIncludes.PrimitiveTypes))
{
foundTypes = foundTypes.Concat(FindPrimitiveTypes());
}
return foundTypes;
}
示例15: Index
//[Route("~/")]
//[Route("")]
public ActionResult Index()
{
List<ArticleModel> articles = new List<ArticleModel>();
user = (Users)Session["User"];
// if (ModelState.IsValid)
// {
ConnManager connManager = new ConnManager();
if(user!= null && user.UserId == 1)
articles = connManager.GetArticles("Select * from VwArticles order by articleId desc");
else
articles = connManager.GetArticles("Select * from VwArticles where IsDisplay =1 order by articleId desc");
// }
PagingInfo info = new PagingInfo();
info.SortField = " ";
info.SortDirection = " ";
info.PageSize = 7;
info.PageCount = Convert.ToInt32(Math.Ceiling((double)(articles.Count/info.PageSize)));
info.CurrentPageIndex = 0;
// var query = articles.OrderByDescending(c => c.ArticleID).Take(info.PageSize);
var query = articles.AsQueryable();
query = query.Skip(info.CurrentPageIndex * info.PageSize).Take(info.PageSize);
ViewBag.PagingInfo = info;
return View(query.ToList());
}