linq-to-entities

Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'

泪湿孤枕 提交于 2019-12-17 22:45:08
问题 I have a method: public DzieckoAndOpiekunCollection GetChildAndOpiekunByFirstnameLastname(string firstname, string lastname) { DataTransfer.ChargeInSchoolEntities db = new DataTransfer.ChargeInSchoolEntities(); DzieckoAndOpiekunCollection result = new DzieckoAndOpiekunCollection(); if (firstname == null && lastname != null) { IList<DzieckoAndOpiekun> resultV = from p in db.Dziecko where lastname == p.Nazwisko **select** new DzieckoAndOpiekun( p.Imie, p.Nazwisko, p.Opiekun.Imie, p.Opiekun

Entity Framework T-Sql “having” Equivalent

风流意气都作罢 提交于 2019-12-17 20:04:38
问题 How can I write a linq to entities query that includes a having clause? For example: SELECT State.Name, Count(*) FROM State INNER JOIN StateOwner ON State.StateID = StateOwner.StateID GROUP BY State.StateID HAVING Count(*) > 1 回答1: Any reason not to just use a where clause on the result? var query = from state in states join stateowner in stateowners on state.stateid equals stateowner.stateid group state.Name by state.stateid into grouped where grouped.Count() > 1 select new { Name = grouped

The type appears in two structurally incompatible initializations within a single LINQ to Entities query

时光怂恿深爱的人放手 提交于 2019-12-17 19:57:51
问题 I'm trying to build something like conditional queries to get only needed data from the underlying database. Currently I have the following query (which works fine) var eventData = dbContext.Event.Select(t => new { Address = true ? new AnonymousEventGetAddress { AddressLine1 = t.Address.AddressLine1, CityName = t.Address.AddressCityName } : new AnonymousEventGetAddress(), }); If I change it to var includeAddress = true; // this will normally be passed as param var eventData = dbContext.Event

Reusable Calculations For LINQ Projections In Entity Framework (Code First)

[亡魂溺海] 提交于 2019-12-17 19:49:54
问题 My domain model has a lot of complex financial data that is the result of fairly complex calculations on multiple properties of various entities. I generally include these as [NotMapped] properties on the appropriate domain model (I know, I know - there's plenty of debate around putting business logic in your entities - being pragmatic, it just works well with AutoMapper and lets me define reusable DataAnnotations - a discussion of whether this is good or not is not my question). This works

LINQ Dynamic Query Library

廉价感情. 提交于 2019-12-17 19:28:20
问题 I am building an ASP.Net MVC 3 application with Entity Framework 4. When the two pieces of code below are executed, both variables (query1 and query2) have a return type of System.Data.Objects.ObjectQuery<Asset.Model.Equipment> Query1 uses a direct instance of the ObjectContext, however, Query2 uses a repository pattern, ie, it calls GetEquipment in EquipmentService, which in turns calls the same named method in Equipment Repository. Both the methods in the Service and Repository return

Linq 2 SQL or Linq Entities

試著忘記壹切 提交于 2019-12-17 19:03:31
问题 I am starting to design a new application and what I am wondering is peoples opinions on Linq2SQL or Linq2Entities and what they feel is the better technology for rapid development. I am also doing some research into ADO.net data services. 回答1: I'm a big fan of LINQ to SQL if you meet the following design requirements: MS SQL Server as the DB engine RAD development 1 - 1 class mapping is all that's required I've not done a whole lot of work with Entity Framework but from what I know and what

The version of SQL Server in use does not support datatype datetime2?

一曲冷凌霜 提交于 2019-12-17 18:26:10
问题 An error occurred while executing the command definition. See the inner exception for details. bbbbInnerException:aaaa System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2'. at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior

Howto use predicates in LINQ to Entities for Entity Framework objects

南笙酒味 提交于 2019-12-17 16:14:07
问题 I'm using LINQ to Entities for Entity Framework objects in my Data Access Layer. My goal is to filter as much as I can from the database, without applying filtering logic to in-memory results. For that purpose Business Logic Layer passes a predicate to Data Access Layer. I mean Func<MyEntity, bool> So, if I use this predicate directly, like public IQueryable<MyEntity> GetAllMatchedEntities(Func<MyEntity, Boolean> isMatched) { return qry = _Context.MyEntities.Where(x => isMatched(x)); } I'm

Create LINQ to entities OrderBy expression on the fly

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 15:46:12
问题 I'm trying to add the orderby expression on the fly. But when the query below is executed I get the following exception: System.NotSupportedException: Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context. The strange thing is, I am query exactly those primitive types only. string sortBy = HttpContext.Current.Request.QueryString["sidx"]; ParameterExpression prm = Expression.Parameter(typeof

Linq when using GroupBy, Include is not working

故事扮演 提交于 2019-12-17 15:39:45
问题 include matchparticipants is not working. It always says Null when I debug. But when I put the GroupBy in comment it works fine. I am using Entity framework 4.3.1 with code-first. Entities: public class Match { [ScaffoldColumn(false)] public int MatchId { get; set; } [Required(ErrorMessage = "Matchtype is a required field")] public int Scheme { get; set; } [Required] [DefaultValue(false)] public bool Finished { get; set; } public int Round { get; set; } // Relations [Required] public Category