entity-framework

How to Optimize Code Performance in .NET [closed]

爱⌒轻易说出口 提交于 2020-01-06 03:18:25
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I have an export job migrating data from an old database into a new database. The problem I'm having is that the user population is around 3 million and the job takes a very long time to complete (15+ hours). The machine I am using only has 1 processor so I'm not sure if threading

Transform data using c# during Entity Framework migration

故事扮演 提交于 2020-01-06 03:10:07
问题 Is it possible to transform data stored in a column using a calculation performed in c# during an Entity First database migration? Currently, I have a column named Content of type nvarchar . I'd like to replace it with a column named ContentBinary of type varbinary , copying the content of each row in the process, but also transforming the content. Specifically, I want to convert the string to a UTF-8 encoding and then compress it. I know that the DbMigration class allows for transformation /

EF - associated entity is trying to add to the database when adding an entity

南笙酒味 提交于 2020-01-06 03:08:25
问题 This question is related to: Saving an explicit entity through Entity Framework Basically, Jcl's approached worked me. But there's another issue when trying to save the changes, because it tries to insert a duplicate entity which I have set as a foriegn key. I'm reading location objects from an Excel file, and construct location objects. I need to set the TimeZone property of the location. There's a timezone table, and the timezoneid is set as the foreign key in the location table. TimeZone

How to delete a single row from database using linq query?

拈花ヽ惹草 提交于 2020-01-06 01:56:07
问题 This is my table ts_grp_perm_mapping grp_permid grp_id perm_id 22 4 1 23 2 2 This is my code to delete row. usr_groupId below is grp_id in above table. usr_doctypeids below is perm_id in above table. public int saveNewUser(int usr_groupId, int usr_doctypeids) { ts_grp_perm_mapping tm = db.ts_grp_perm_mapping.Find(usr_groupId); db.ts_grp_perm_mapping.Remove(tm); int rowiseffected=db.SaveChanges(); return rowiseffected; } When I trace my tm shows null, and error pops up like values cannot be

How to debug Entity Framework migration LoaderExceptions?

↘锁芯ラ 提交于 2020-01-06 01:54:28
问题 I'm trying to run update-database in an Entity Framework 5 project that runs on other machine. I downloaded the code, rebuilt the project and when I run update-database I get an error like this: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly

Cannot define composite PK with Fluent API in VB.NET

此生再无相见时 提交于 2020-01-06 01:54:25
问题 I am trying to define a composite PK for a class where one of the columns is a FK to another table. The code compiles without any errors but when I try to migrate the changes I get the following error PM> Update-Database -Force -TargetMigration:0 Specify the '-Verbose' flag to view the SQL statements being applied to the target database. System.InvalidOperationException: The properties expression 'x => new VB$AnonymousType_0`2(RtepNumber = x.RtepNumber, ContractId = x.Contract.ContractId)' is

Manually map POCO to existing Table using Entity Framework

馋奶兔 提交于 2020-01-06 01:53:07
问题 I have an existing database table Movie . Now I want to write a POCO Movie.cs which will map to that table. I want to have control over the mapping partially because I'm trying to learn more about EF. The Movie table has 3 fields: Title VARCHAR(255,), ReleaseDate DATETIME, Price MONEY . What would my DbContext - derived class look like for this? Coming from a Java/Hibernate background, I figured I would just map fields in the POCO to cols in the table, but it doesn't seem that straight

Can't compare dates using SQLite with EF6

别说谁变了你拦得住时间么 提交于 2020-01-06 01:52:22
问题 I'm trying to compare dates using Linq to Entities on a SQLite database. The following code works, but I need to trim off the time portion to get the correct results. return (from c in Context.Car join d in Context.Driver on c.CarID equals d.DriverID join r in Context.Rides on c.CarID equals r.RideID into rideJoin from rides in rideJoin.DefaultIfEmpty() where c.IsActive && d.IsActive group rides by new { c.CarID, d.FullName, d.HireDate, d.FirstPayRiseDate } into grp select new MyCustomClass {

Can't extend IdentityUserRole.cs to add new composite key to dbo.AspNetUserRoles table ASP.NET Identity 2.1

爷,独闯天下 提交于 2020-01-06 01:32:07
问题 I am trying to build Membership system using ASP.NET Identity 2.1, ASP.NET Web API 2.2 and i need to extend IdentityUserRole to add another PK to its table like that: public class ApplicationUserRoles : IdentityUserRole { public Guid ProjectId { get; set; } public Project Project { get; set; } } public class Project { public Project() { ProjectId = new Guid(); } public string ProjectName { get; set; } [Key] public Guid ProjectId { get; set; } } And in the DBcontext class I added : protected

Entity Framework code-first: querying a view with no primary key

帅比萌擦擦* 提交于 2020-01-06 01:29:12
问题 Our customer has given the access to views in which there is no primary key is defined. I know Entity Framework needs a primary key for table to identify. But for views not having primary key is it still possible to query. I try to find but always Entity Framework gives error saying: Error: : EntityType 'ViewWeight' has no key defined. Define the key for this EntityType. I understand key is important for tables, but for views just to read is there any hack or way to read the values without