ef-database-first

Binding ListBox with a model in MVC3

最后都变了- 提交于 2019-11-30 18:10:21
问题 My model is public class SiteConfig { public SiteConfig() { } public int IdSiteConfig { get; set; } public string Name { get; set; } public byte[] SiteLogo { get; set; } public string Brands { get; set; } public string LinkColour { get; set; } public IEnumerable<SiteBrand> SiteBrands { get; set; } } and public class SiteBrand { public int Id { get; set; } public int SiteId { get; set; } public int BrandId { get; set; } public Brand Brand { get; set; } public SiteConfig SiteConfig { get; set;

Entity Framework - Entity read-only property mapped to a column of related table

拈花ヽ惹草 提交于 2019-11-30 09:43:57
I have interesting problem to solve but, although common, it looks like it's not easily achievable with Entity Framework. There are two tables: Player(Id,TeamId,FirstName,LastName) Team(Id, Name, IsProfessional) Player can belong only to one team. Using TPT (DB first), we have two classes mapped to those tables: public class Player { public int Id{get;set;} public int TeamId{get;set;} public string FirstName{get; set;} public string LastName{get; set;} public Team Team{get;set;} } public class Team { public int Id{get; set;} public string Name{get;set;} public bool IsProfessional{get;set;}

Unable to run EF5 migration with existing database

牧云@^-^@ 提交于 2019-11-30 08:32:00
问题 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

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

核能气质少年 提交于 2019-11-30 06:48:40
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 multiple Include method calls? Write a single method GetCategoryById and include all items inside

Updating model in EF Database First project

梦想的初衷 提交于 2019-11-30 03:11:16
问题 I've inherited a project which uses Entity Framework Database First. I'm trying to work out how to update the model classes when I update the database but I can't figure it out. What I've done so far is added a column called Test to a table in the database, then in Model Browser I've right clicked on the .edmx file and selected Update Model from Database and then followed the options in the wizard that appears. Now, when I look at the database relationship diagram that is rendered when

Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project

[亡魂溺海] 提交于 2019-11-30 02:20:00
问题 I've been researching a lot online but did not find a proper solution. I was trying to use Entity Framework Core with MySQL by using database-first scaffold method to mapping table model while always received this error when applied the command Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option. This is the command I am using

How to use an existing enum with Entity Framework DB First

限于喜欢 提交于 2019-11-30 00:02:35
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 reference 'OtherNamespace.MyEnum'.'. OtherNamespace.MyEnum is referenced by my project. How do you do it?

EF 6 database first: How to update stored procedures?

让人想犯罪 __ 提交于 2019-11-29 22:49:40
We are using Entity Framework 6.0.0 and use database first (like this) to generate code from tables and stored procedures. This seems to work great, except that changes in stored procedures are not reflected when updating or refreshing the model. Adding a column to a table is reflected, but not adding a field to a stored procedure. It is interesting that if I go to the Model Browser , right click the stored procedure, select Add Function Import and click the button Get Column Information we can see the correct columns. This means that the model knows of the columns, but does not manage to

How to sync model after using Code First from Database using Entity Framework 6.1 and MVC 5?

霸气de小男生 提交于 2019-11-29 19:42:32
Assumptions Using EF 6.1, MVC 5, VS 2013, C# I have an existing database model designed in Toad DM for SQL Server and it's very important keep it always updated Steps and Notes Using ADO.NET Entity Data Model I chose Code First from Database ( new feature in EF 6.1 ) to generate the models. Note: Model classes and DbContext class generated successfuly but NO .edmx or .tt file was generated . Next I added a new scaffold item: MVC 5 Controllers with views, using Entity Framework. Note: Success, controllers and views generated Question From now on I don't want to use Code First to update my

Add relationships to the ApplicationUser class in ASP.NET Identity (Database First)

非 Y 不嫁゛ 提交于 2019-11-29 15:27:40
I'm using ASP.NET Identity (Database First) in my ASP.NET MVC application. I followed the instructions here , to set up the ASP.NET Identity with database first approach. My AspNetUsers table has a relationship with the Employee table (The Employee table has a UserId foreign key, and the AspNetUsers entity has an ICollection<Employee> property). I would like to add the ICollection<Employee> property to the ApplicationUser, like below: public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim> { public ICollection<Employee> Employees { get; set; } public