linq-to-entities

How to bind a query with a join to a DataGridView?

泪湿孤枕 提交于 2019-12-23 01:24:16
问题 Right now, I have created a new Object data source based off from an Object Context from the entity model. I then created a BindingSource and a DataGridView set to this BindingSource. I can add columns which are bound to the data from the TraceLine table. When I set the DataSource, I see values in those columns. However, I can’t seem to get the data from the joined table. How do I bind a DataGridView to a query that has a join? using (var entities = new MyEntities()) { var lines = from t in

Has anyone used lucene.net with Linq-to-Entities?

独自空忆成欢 提交于 2019-12-23 01:18:51
问题 If anyone has done this, please let me know. I don't know anything about lucene.net. I have never used it, but I heard about it. I was wondering how something like that would integrate with the Linq entity framework? 回答1: Check out Linq to Lucene project. 回答2: Check this article in linq to lucene discussion Linq to Lucene for Entity Framework working with entity framework only one class add 来源: https://stackoverflow.com/questions/153290/has-anyone-used-lucene-net-with-linq-to-entities

How To Count Associated Entities using Where In Entity Framework

你离开我真会死。 提交于 2019-12-23 00:53:19
问题 I have this: var queryResult = (from post in posts select new { post, post.Author, post.Tags, post.Categories, Count = post.Comments.Count() }).ToList(); But I need something like this: var queryResult = (from post in posts select new { post, post.Author, post.Tags, post.Categories, Count = post.Comments.Where(x=>x.IsPublic).Count() }).ToList(); But post.Comments is a ICollection 回答1: How about using Enumerable.Cast<T>() like this ? var queryResult = (from post in posts select new { post,

WCF RIA Services - Loading multiple entities

大憨熊 提交于 2019-12-22 18:39:09
问题 I'm looking for a pattern to solve the following problem, which I imagine is common. I am using WCF RIA Services to return multiple entities to the client, on initial load. I want both entities to load asyncrhonously, so as not to lock the UI, and I'd like to leverage RIA Services to do this. My solution, below, seems to work. Will I run into problems/limitations with this approach? Is there a better pattern for this? Thanks! //create proxy to Domain Service var proxy = new RIAService.Web

How do I filter related Child Record

烈酒焚心 提交于 2019-12-22 15:50:24
问题 I am using RIA services. I need to select a parent entity ( UnitOccupier ) which has a number of related child entities( UnitOccupierDetails ). I need to filter the child entities to return a single record. How do I do this? var q = from uo in _unitOccupierContext.GetUnitOccupierQuery() where uo.UnitOccupierDetails.???? ---> I cant get to the child properties here Thanks 回答1: You cannot include a filtered child collection of the selected parent. You can only include either the full collection

The LINQ expression node type 'Invoke' is not supported in LINQ to Entities

穿精又带淫゛_ 提交于 2019-12-22 13:56:23
问题 public CategoryViewModel GetSingle( Expression<Func<CategoryViewModel, bool>> where) { Expression<Func<DAL.EntityModels.Category, CategoryViewModel>> converter = c => ToBll(c); var param = Expression.Parameter(typeof(DAL.EntityModels.Category), "category"); var body = Expression.Invoke(where, Expression.Invoke(converter, param)); var lambda = Expression.Lambda<Func<DAL.EntityModels.Category, bool>>(body, param); return (CategoryViewModel )_categoryRepository.GetSingle(lambda); } The code

Building dynamic where clause, Linq To Sql

泄露秘密 提交于 2019-12-22 11:17:18
问题 I am using EF Code first 4.2, What sort of solution do you propose when the where clause needs to be dynamically built? Yet Include functionality would be highly required: var results = db.Set<dynamicType>.Where("dynamic conditions").Include("...."); The dynamic condition above needs to lookup to another table to filter the records: If I wanted to write that in Linq expression it would be something like: var result = db.Set<Contact>().Where(c=>c.AccountId == _Id_param || db.Set<LinkTable>()

Concat IQueryable collections in one db request

旧时模样 提交于 2019-12-22 10:58:19
问题 I use entity framework.I need concat two collections.For example: IQueryable<SomeType> collection1 = context.Entiies.Where(predicate); IQueryable<SomeType> collection2 = context.Entiies.Where(otherPredicate); var result = collection1.concat(collection2).toList(); //1 var result = collection1.union(collection2).toList; //2 Both 1 and 2 variant will do 2 requests in database,because these methods need IEnumerable as parameter.So,the question is can I concat two Iqueryble collections with one

Entity framework - select by multiple conditions in same column - referenced table

余生长醉 提交于 2019-12-22 10:55:45
问题 Example scenario: Two tables: order and orderItem , relationship One to Many. I want to select all orders that have at least one orderItem with price 100 and at least one orderItem with price 200. I can do it like this: var orders = (from o in kontextdbs.orders join oi in kontextdbs.order_item on o.id equals oi.order_id join oi2 in kontextdbs.order_item on o.id equals oi2.order_id where oi.price == 100 && oi2.price == 200 select o).Distinct(); But what if those conditions are user generated?

Entity Framework fetch Top 10 rows

末鹿安然 提交于 2019-12-22 10:31:38
问题 I have a 3 tables in SQL database tblVideos : VideoID int PK Title varchar(100) Decription varchar(100) tblTags : TagID int PK TagText varchar(100) tblVideosToTags : VideoID int PK, FK to Videos TagID int PK, FK to Tags In Entity Framework (v6-latest-nightly-build) I have 2 classes Video and Tag with many-to-many relationships. I need a help with building a LINQ to Entities or LINQ to SQL query which meets following conditions: Top 10 records from Tags, which is mostly used. So probably some