entity-framework-6

Exceptions when rolling back a transaction - connection already closed?

偶尔善良 提交于 2019-12-05 01:29:34
Using Entity Framework 6.0.0, I'm seeing an exception when closing a transaction. We'd been having problems with concurrent changes to the table, so I wrapped it in a transaction, and now I'm getting exceptions on rollback. The code: public LockInfo getSharedLock(string jobid) { using (var myDbContext = new MyDbContext()) { using (var transaction = myDbContext.Database.BeginTransaction()) { try { this.logger.log("Attempting to get shared lock for {0}", jobid); var mylocks = myDbContext.joblocks.Where(j => j.customerid == this.userContext.customerid) .Where(j => j.jobid == jobid) .Where(j => j

Entity Framework 6: Adding child object to parent's list vs. setting child's navigation property to parent

走远了吗. 提交于 2019-12-05 01:25:35
I have an existing database with two tables MailServers and MailDomains in it. MailDomains has the foreign key column MailServerId pointing to the Id primary key column in MailServers . So we have a one-to-many-relationship here. I followed this article and created my Entity Framework POCOs via the "Code first from database" model in the Entity Data Model Wizard. This produced the following two C# classes: public partial class MailServer { public MailServer() { MailDomains = new HashSet<MailDomain>(); } public int Id { get; set; } public virtual ICollection<MailDomain> MailDomains { get; set;

How does the SQLite Entity Framework 6 provider handle Guids?

我与影子孤独终老i 提交于 2019-12-05 01:20:17
I am porting our product's database to SQLite from another product that supported Guids. As we know, SQLite does not support Guids. I've got created an entity framework 6 model from my database (database first) and I need to build a query from C# that compares the Guid to one passed from the code. The thing is I can't find any documentation on how the SQLite Entity Framework provider handles Guids. A web search didn't find anything useful for me, either. Just questions about using Entity Framework with SQLite. Can anybody point me to the documentation, or maybe tell me how to work with Guids

IdentityStoreManager could not be found after upgrading Microsoft.AspNet.Identity to rc1

邮差的信 提交于 2019-12-05 00:41:10
After Upgrading Microsoft.AspNet.Identity.Core to 1.0.0-rc1 several errors appear in the AccountController.cs And AppModel.cs classes which are generated by the default MVC5 templates in Visual Studio 2013. Are there any release notes to explain how to resolve the breaking changes? Update the following nuget packages: Microsoft ASP.NET Identity EntityFramework version="1.0.0-rc1" Microsoft.Owin.Security version="2.0.0-rc1" Microsoft.Owin.Security.OAuth version="2.0.0-rc1" Get these: Microsoft.AspNet.Identity.Owin version="1.0.0-rc1" Microsoft.Owin.Host.SystemWeb version="2.0.0-rc1" Then you

Entity Framework 6 Update Graph

我怕爱的太早我们不能终老 提交于 2019-12-05 00:33:00
What is the correct way to save a graph of objects whose state you don't know? By state I mean whether they are new or existing database entries that are being updated. For instance, if I have: public class Person { public int Id { get; set; } public int Name { get; set; } public virtual ICollection<Automobile> Automobiles { get; set; } } public class Automobile { public int Id { get; set; } public int Name { get; set; } public short Seats { get; set; } public virtual ICollection<MaintenanceRecord> MaintenanceRecords { get; set ;} public virtual Person Person { get; set; } } public class

Stored Procedure returns incorrect scalar value of -1, instead of return value

被刻印的时光 ゝ 提交于 2019-12-04 23:54:33
问题 I am trying to return a scalar value from a stored procedure. I actually want to return the ID of a newly created record, but I have simplified my problem down to a stored procedure that takes an int and attempts to return that same int . This always returns -1. Thank you very much for your help. Web API Controller call var idtest = dbconn.my_return_int(123); The stored procedure: ALTER PROCEDURE [dbo].[my_return_int] @ID int AS BEGIN SET NOCOUNT ON; DECLARE @return as int SET @return = -999

ProviderManifestToken 2008 or 2012

∥☆過路亽.° 提交于 2019-12-04 23:38:04
问题 The application: .NET 4.5 C# Uses EF6 with database first approach Supports SQL Server 2008R2, 2012 and 2014 This question is regarding the ProviderManifestToken attribute of the auto-generated edmx file. Depending on which version of the database is used (different developers have different version of the database) to update the model from the database, the value of the ProviderManifestToken attribute either gets set to 2008 or 2012. Until we discontinued support for SQL Server 2005, we made

What logic determines the insert order of Entity Framework 6

时光怂恿深爱的人放手 提交于 2019-12-04 23:30:48
So, I have a DBContext, and I am doing the following operations: dbContext.SomeTables1.Add(object1) dbContext.SomeTables2.AddRange(objectArray2) dbContext.SomeTables3.AddRange(objectArray3) dbContext.SaveChanges(); The EF doesn't insert the db records in this order, it inserts them in a random order. To insert them in the same order, I have to do a dbContext.SaveChanges() after each addition. This is not an efficient solution and in my case, it is taking 10 seconds to do all my inserts, while the random order with one save takes around 3 seconds. N.B. I need the right order to solve a deadlock

“Update-Database” command fails with TimeOut exception

◇◆丶佛笑我妖孽 提交于 2019-12-04 22:50:01
I'm using EF migrations and have a table with a lot of data. I need to change MaxLength of a concrete column (it hadn't length constraints). ALTER TABLE MyDb ALTER COLUMN [MyColumn] [nvarchar](2) NULL And this command fails with TimeOut exception. Tried to setup CommandTimeout i nDbContext constructor without any luck. Is there any way to disable or setup timeout for Package Manager Console EF commands? Alternatively script out the change by using Update-Database -script You can then take the script and run it using SQL Management Studio against the database. Found solution by myself. Since

How can I create a MetadataWorkspace using metadata loading delegates?

☆樱花仙子☆ 提交于 2019-12-04 21:47:46
I followed this example Changing schema name on runtime - Entity Framework where I can create a new EntityConnection from a MetaDataWorkspace that I then use to construct a DbContext with a different schema, but I get compiler warnings saying that RegisterItemCollection method is obsolete and to "Construct MetadataWorkspace using constructor that accepts metadata loading delegates." How do I do that? Here is the code that is working but gives the 3 warnings for the RegsiterItemCollection calls. I'm surprised it works since warning says obsolete not just deprecated. public static