entity-framework-5

How to set Arithabort on in Linq to Entities?

浪尽此生 提交于 2019-12-01 13:07:06
I've found tons of answers for how to set Arithabort on in Linq to SQL, but nothing in Linq to Entities. In Linq to SQL, you can do this: using (var conn = new SqlConnection(connectionString)){ cmd = conn.CreateCommand(); cmd.Connection.Open(); cmd.CommandText = "set arithabort on;"; cmd.ExecuteNonQuery(); // Line 5 using (var db = new MyDataContext(conn)) { ... } } but if I do exactly the same thing, just substituting EntityConnection from SqlConnection in the code snippet above, I get a runtime error on Line 5: The query syntax is not valid. Near identifier 'arithabort', line 1, column 5. I

ASP.NET Webforms CRUD scaffolding with Entity Framework 5

China☆狼群 提交于 2019-12-01 12:03:17
Back in Feb MS introduced: http://www.nuget.org/packages/Microsoft.AspNet.Scaffolding.WebForms/ http://blogs.msdn.com/b/webdev/archive/2013/02/20/pre-release-of-asp-net-scaffolding-with-a-web-forms-scaffold-generator.aspx but it appears that it will be dropped from VS2013 ASP.NET Web Forms Scaffolding feature missing in VS 2013 RC I followed the instructions here http://dotnetguts.blogspot.com.au/2013/06/scaffolding-for-aspnet-webforms.html to install the package under Visual Studio 2012 but when I go to add a scaffold the scaffold generator drop down is empty. So my question is has anyone

Linq To Entities Compare Value Against List<int>

只愿长相守 提交于 2019-12-01 11:45:55
I am using Entity Framework 5.0 , and I have a problem with a LINQ query. I have the following method that accepts an integer value which is then passed into the query. This works fine. public IList<tblcoursebooking> GetStandardReport(int AttendanceID) { return _UoW.tblcoursebookingRepo.All .Where(cb => cb.Attended.Equals(AttendanceID) .ToList(); } However, I need to change the method so that it accepts a List of integers , and then pulls out all records where Attended is equal to any of the List of integers. Something like this public IList<tblcoursebooking> GetStandardReport(List<int>

How can I recursively Include ALL navigable properties to emulate Lazy Loading

谁说我不能喝 提交于 2019-12-01 11:25:33
To emulate Lazy Loading, I would like to have a method that recursively Include's the complete object graph via Eager Loading so that upon loading the entity, all of its related data is loaded as well. From MSDN documentation: To include a single reference: query.Include(e => e.Level1Reference). To include a single collection: query.Include(e => e.Level1Collection). To include a reference and then a reference one level down: query.Include(e => e.Level1Reference.Level2Reference). To include a reference and then a collection one level down: query.Include(e => e.Level1Reference.Level2Collection).

Combine two EF Queries, Unable to cast object of type System.Data.Entity.Infrastructure.DbQuery to System.Collections.Generic.IEnumerable

泪湿孤枕 提交于 2019-12-01 11:18:34
I have two Entity Framework queries, each returning two columns, and i would like to concat or join the results of both queries for the reason of binding, I have tried the Concat method but it's throwing: Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[VB$AnonymousType_3`2[System.String,System.String]]' to type 'System.Collections.Generic.IEnumerable`1[VB$AnonymousType_2`2[System.String,System.String]] '. Here is my code: Dim r = (From PropertyDefinitions In econtext.PropertyDefinitions Join ProductPropertyValues In econtext.ProductPropertyValues On

EF5 does not create enum columns

我怕爱的太早我们不能终老 提交于 2019-12-01 10:58:20
问题 I have a model like this: namespace Ad.NegCred.Data.Model { public enum DataKind { F, //Takibe alınıp henüz tahsil edilmeyen ferdi kredi bildirimi FA, //Aynı dönemde takibe alınan ve tahsil edilen ferdi kredi bildirimi FF, //daha önceki dönemlerde takibe alındığı bildirilmiş ferdi kredi tahsil bildirimi K, //Takibe alınıp henüz tahsil edilmeyan kredi kartı KA, //Aynı dönemde takibe alınan ve tahsil edilen kredi kartı KF //Daha önceki dönemlerde takibe alındığı bildirilmiş kredi kartı tahsil

How to set Arithabort on in Linq to Entities?

ⅰ亾dé卋堺 提交于 2019-12-01 10:52:25
问题 I've found tons of answers for how to set Arithabort on in Linq to SQL, but nothing in Linq to Entities. In Linq to SQL, you can do this: using (var conn = new SqlConnection(connectionString)){ cmd = conn.CreateCommand(); cmd.Connection.Open(); cmd.CommandText = "set arithabort on;"; cmd.ExecuteNonQuery(); // Line 5 using (var db = new MyDataContext(conn)) { ... } } but if I do exactly the same thing, just substituting EntityConnection from SqlConnection in the code snippet above, I get a

Using stored procedure in Entity Framework 5 with complex type?

孤街浪徒 提交于 2019-12-01 10:03:44
问题 I have the following stored procedure in SQL Server: ALTER PROCEDURE [dbo].[FullTextSearchOnContent] ( @SearchText NVARCHAR(200), @LanguageId INT , @ContentStatusId INT , @ResultCount INT ) AS BEGIN SET FMTONLY OFF; SET NOCOUNT ON; IF (@SearchText IS NULL) OR (@SearchText = '') OR (@ResultCount IS NULL) OR (@ResultCount = 0) RETURN NULL; SELECT DISTINCT TOP(@ResultCount) C.Id AS ContentId, C.ImagePath AS ContentImagePath, C.IsSpecial,C.LanguageId,C.LockCommenting,C.RegistrationDate AS

How can I recursively Include ALL navigable properties to emulate Lazy Loading

放肆的年华 提交于 2019-12-01 09:40:41
问题 To emulate Lazy Loading, I would like to have a method that recursively Include's the complete object graph via Eager Loading so that upon loading the entity, all of its related data is loaded as well. From MSDN documentation: To include a single reference: query.Include(e => e.Level1Reference). To include a single collection: query.Include(e => e.Level1Collection). To include a reference and then a reference one level down: query.Include(e => e.Level1Reference.Level2Reference). To include a

“The operation cannot be completed because the DbContext has been disposed” exception with lazy load disabled

僤鯓⒐⒋嵵緔 提交于 2019-12-01 09:06:52
Given: public ActionResult List() { using (var unitOfWork = new UnitOfWork()) { var result = unitOfWork.Repository.Find<EntityAddress>(a => a.PostalCode == "80001"); //return View(result.ToList());//NO Exception raised with ToList() return View(result);//EXCEPTION RAISED IN VIEW DURING ITERATION } } UnitOfWork is disposable and handles disposal of my DbContext. It also disables lazy loading in the constructor: public UnitOfWork() { _dbContext.Configuration.LazyLoadingEnabled = false; Repository = new GenericRepository<MyEntities>(_dbContext); } public void Dispose() { Repository.Dispose(); }