ef-database-first

Entity Framework Database first How to alter entities to make them derive from a base class

徘徊边缘 提交于 2019-12-10 14:18:29
问题 I have a database already full of tables with data in them. What I have seen is that all tables have 5 columns in common: Id-long, key IsDeleted, bit DateDeleted, SmallDatetime LastUpdated, SmallDatetime LastUpdatedUser, nvarchar Now, there are some common operations that are done based on those fields which currently are replicated everywhere What I want is to create a base class containing just these common attributes and the methods done to them and make every other entity derive from this

Entity Framework 6.1 : The given key was not present in the dictionary

南楼画角 提交于 2019-12-10 10:44:42
问题 I have a table with some relations, the program works fine until I add a new relation between this table and customer table, the ddl for PermissionCode Table (first table) is as below: CREATE TABLE [dbo].[PermissionCode] ( [Id] int NOT NULL IDENTITY(1,1) , [Salt] varchar(3) COLLATE Turkish_CI_AS NOT NULL , [Code] nvarchar(12) COLLATE Turkish_CI_AS NOT NULL , [StartDate] date NULL , [EndDate] date NULL , [TypeId] int NOT NULL , [UserId] nvarchar(128) COLLATE Turkish_CI_AS NULL , [OwnerId] int

Custom properties in EF database first

岁酱吖の 提交于 2019-12-10 10:15:36
问题 Good day! I have created an EF model from database using database first aproach, and added myself several read only properties to entity class generated by EF which are not in database. Every time I update my model adding data from new tables I loose properties created, so I have to recreate them. As an example in database I have property isFemale but in my class I've created public string Gender { get { if(isFemale) return "female"; else return "male"; } } My question is there a way to

Entity Framework 4.1 Database First Dependency Injection Unit of Work

▼魔方 西西 提交于 2019-12-09 01:45:00
问题 Ok, there are tons of examples using unit of work with dependency injection for Code First, using generic repositories and all that good stuff. Does anyone have an example doing this with Database First (edmx with dbContext Generator (T4)), Stored Procedures as Function Imports, Unit of Work with dependency injection. 回答1: The context for code first or dbfirst will be the same (DbContext). Stored procedures are mapped in your repository instead of calling context.Customers you call context

Ignore certain columns on update

断了今生、忘了曾经 提交于 2019-12-08 09:01:03
问题 Hello I have something like this: public ActionResult Edit(int id) { var movie = (from m in _db.Movies where m.Id == id select m).First(); return View(movie); } [HttpPost] public ActionResult Edit(Movie movie) { try { var originalMovie = (from m in _db.Movies where m.Id == movie.Id select m).First(); _db.Movies.ApplyCurrentValues(movie); _db.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } } This example was taken from Proper way to Edit an entity in MVC 3 with the

EF6 ToListAsync does not run async but blocks the thread

ε祈祈猫儿з 提交于 2019-12-07 14:21:26
问题 To increase my page performance I wanted to run a few queries asynchronously. I upgraded to EF6 because it natively supports this feature by exposing async methods. I couldn't get the queries to fire simultaneously so i boiled my code down to this simple example : var sw = new Stopwatch(); sw.Start(); var dummy = context.Set<CA_Event_Person>().Take(200).ToListAsync(); sw.Stop(); Logger.Debug("attempt nr 1 : " + sw.ElapsedMilliseconds); var result = await dummy; My exception was that the

Why is EF DataBase First not use getdate()?

爱⌒轻易说出口 提交于 2019-12-07 06:07:28
问题 I am using EF 4.1 with database first. Example table: CREATE TABLE dbo.Product( [ID] [int] IDENTITY(1,1) not null, Title nvarchar(200) not null, CreateDate datetime not null default(getdate()), ) When I add a new row, I get an exception about DateTime type overflow. The getdate() of database settings is invalid. I must be set the storeGeneatePattern property of the createdate field to Computed . Is there any way to let the EF automatically generated the DateTime column without manually set??

EntityFramework 5 - Getting value cannot be null parameter name: font error while using the designer

安稳与你 提交于 2019-12-06 19:15:17
问题 I'm getting a strange error while using EF 5 using a Database First approach on the designer. The error is saying 'value cannot be null parameter name: font'. I also get a big red X over the design area. I'm not exactly sure how the designer generated this error, and to this point, I've only used the designer to create my edmx. Thoughts? This is with VS 2012 RTM version. 回答1: I was able to resolve the same error by simply restarting Visual Studio. 回答2: I was able to fix this by repairing the

Entity framework 6 usetransaction databasefirst throws UnintentionalCodeFirstException

时间秒杀一切 提交于 2019-12-06 15:31:56
I'm trying to execute the following : SqlConnection cnSql = new SqlConnection(cnstring); cnSql.Open(); SqlTransaction Transactie = default(SqlTransaction); Transactie = cnSql.BeginTransaction(); SqlCommand cmddelbonh = new SqlCommand(); cmddelbonh.Connection = Transactie.Connection; cmddelbonh.Transaction = Transactie; cmddelbonh.CommandText = "update artikelgroepen set OMSN='XXXXX' where ID = 3"; cmddelbonh.ExecuteNonQuery(); using (CXNACC_TESTFIRMA cxn = new CXNACC_TESTFIRMA(cnSql)) { cxn.Database.UseTransaction(Transactie); var myList = cxn.ARTIKELS.Take(100).ToList(); cxn.ARTIKELS.First()

Entity Framework 6.1 : The given key was not present in the dictionary

倾然丶 夕夏残阳落幕 提交于 2019-12-06 06:39:58
I have a table with some relations, the program works fine until I add a new relation between this table and customer table, the ddl for PermissionCode Table (first table) is as below: CREATE TABLE [dbo].[PermissionCode] ( [Id] int NOT NULL IDENTITY(1,1) , [Salt] varchar(3) COLLATE Turkish_CI_AS NOT NULL , [Code] nvarchar(12) COLLATE Turkish_CI_AS NOT NULL , [StartDate] date NULL , [EndDate] date NULL , [TypeId] int NOT NULL , [UserId] nvarchar(128) COLLATE Turkish_CI_AS NULL , [OwnerId] int NULL , [CategoryId] int NULL , [IsActive] bit NOT NULL DEFAULT ((1)) , [InsertIdentifier] varchar(8)