ef-database-first

SQLite DATETIME column with Entity Framework

你。 提交于 2019-11-29 08:01:31
I have an existing SQLite database that I want to use in Entity Framework. However SQLite's weird type system means you can even create table temp(temp datetime); insert into temp values ('whatever'); The dates are stored as Unix time integers. My model classes are autogenerated by Visual Studio, so how do I tell the code generator to handle these dates correctly and not make the application throw String was not recognized as a valid DateTime. exceptions on startup? You have to change your connection string to something like data source="|DataDirectory|\data.sqlite";datetimeformat=UnixEpoch

What is the best practice for multiple “Include”-s in Entity Framework?

依然范特西╮ 提交于 2019-11-29 06:58:48
问题 Let's say we have four entities in data model: Categories, Books, Authors and BookPages. Also assume Categories-Books, Books-Authors and Books-BookPages relationships are one-to-many. If a category entity instance is retrieved from database - including "Books", "Books.BookPages" and "Books.Authors" - this will become a serious performance issue. Moreover, not including them will result in "Object reference is not set to an instance of an object" exception. What is the best practice for using

Unable to run EF5 migration with existing database

我的未来我决定 提交于 2019-11-29 06:56:07
First, I've read these questions/answers: EF-migration message How can I stop Add-Migration checking my database has no pending migrations when using Code-Based migrations? Make EF4.3 Code First Migrations ignore pending migrations These all seem to be for EF versions prior to EF5, and my situation doesn't seem to fit these answers. So, let me describe my situation. My application was originally created using EF4, model first. I designed my database with the GUI designer, and used it to generate my database. I've been running and collecting data into the database for a few months. I really can

How to use an existing enum with Entity Framework DB First

ぃ、小莉子 提交于 2019-11-28 21:04:59
问题 I am using Entity Framework 5, DB first. I know how to define an enum on my model, and set the type of a field to that enum. Now, I have a requirement to map a field MyField to an enum that is defined externally, i.e. not in the EF model ( OtherNamespace.MyEnum ). The designer does not allow me to set the type to anything outside the model. I tried editing the edmx file manually, but that causes an error: Error 10016: Error resolving item 'MyField'. The exception message is: 'Unresolved

The context is being used in Code First mode with code that was generated from an EDMX file

蓝咒 提交于 2019-11-28 05:54:41
问题 I am developing an MVC 5 application with EF 6 database first approach. Now I want my DbContext to access multiple databases based on different Users. For that matter I generated a connection string in Web.Config file as: string str = u.Users.Where(x => x.UserName == HttpContext.User.Identity.Name).First().ConnStr; var configuration = WebConfigurationManager.OpenWebConfiguration("~"); var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");

Using MVC 4 SimpleMembership with an existing database-first EF model

风格不统一 提交于 2019-11-28 05:04:38
I am trying to use SimpleMembership in my MVC 4 for the first time and I already have an existing database and EF5 model created based on it! I searched a lot but I cant find how I could use it in my case and also to have everything under my own model. It would be great if somebody can give me an idea how to do this. Thanks Purely as a point of reference, it might be a good idea to create a new Internet Application template of an ASP.NET MVC 4 Web Application project (i.e. via File > New Project). If you look at the AccountController , as @zms6445 says, it is decorated with an

SQLite DATETIME column with Entity Framework

ε祈祈猫儿з 提交于 2019-11-28 01:44:52
问题 I have an existing SQLite database that I want to use in Entity Framework. However SQLite's weird type system means you can even create table temp(temp datetime); insert into temp values ('whatever'); The dates are stored as Unix time integers. My model classes are autogenerated by Visual Studio, so how do I tell the code generator to handle these dates correctly and not make the application throw String was not recognized as a valid DateTime. exceptions on startup? 回答1: You have to change

DB-First authentication confusion with ASP.NET Web API 2 + EF6

China☆狼群 提交于 2019-11-27 19:09:25
I need to create a Web API C# application for an existing MySQL database. I've managed to use Entity Framework 6 to bind every database table to a RESTful API (that allows CRUD operations) . I want to implement a login/registration system (so that I can implement roles and permissions in the future, and restrict certain API requests) . The MySQL database I have to use has a table for users (called user ) that has the following self-explanatory columns: id email username password_hash It seems that the de-facto standard for authentication is ASP.Net Identity. I have spent the last hour trying

Upgrade from Entity Framework 5 to 6

北城以北 提交于 2019-11-27 17:13:00
After upgrading our project from using Entity Framework 5 to Entity Framework 6 (though NuGets update function) i get the following error on my generated Entities class: Error 1 The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) I understand that this is because the namespace has changed and i can manually fix the error by changing my imports from: using System.Data.Objects; and using System.Data.Objects.DataClasses; To: using System.Data.Entity.Core.Objects; However the file is generated so i need to reapply this fix

Modelling polymorphic associations database-first vs code-first

时间秒杀一切 提交于 2019-11-27 04:37:44
We have a database in which one table contains records that can be child to several other tables. It has a "soft" foreign key consisting of the owner's Id and a table name. This (anti) pattern is know as "polymorphic associations". We know it's not the best database design ever and we will change it in due time, but not in the near future. Let me show a simplified example: Both Event , Person , and Product have records in Comment. As you see, there are no hard FK constraints. In Entity Framework it is possible to support this model by sublassing Comment into EventComment etc. and let Event