database-first

How to add data annotation for entities automatically created by Data-First?

匆匆过客 提交于 2019-12-18 11:57:37
问题 If model-first, we use [MetadataType(typeof(ConceptMetadataSource))] to attach a MetadataSource file which contains all the data annotations like [HiddenInput(DisplayValue = false)] or [Display(Name = "Title")] . For example: [MetadataType(typeof(ConceptMetadataSource))] public partial class Concept ... Now, I am using database-first approach since there is an existing database. This time, the entity classes are automatically created by edmx model. At the beginning of each entity class, there

Entity Framework cant use the DbContext, model being created

江枫思渺然 提交于 2019-12-17 20:57:30
问题 I am using EF 4.1, and I create a normal EF edmx file. I generate it from a DB. When it's been generated I rightclick and select add code generation item, to generate new classes, and use the DbContext instead. I use the template DbContext generator. Everything works fine. Then I trie to query the context: using (var context = new PasDBEntities()) { var client=context.ClientCompanies.SingleOrDefault(_=>_.ID==clientCompanyId); if(client!=null) I have no problem creating a new instance of the

Enums EF 5.0 - Database First

允我心安 提交于 2019-12-17 15:54:25
问题 How can I make it so that my context objects uses the Enum feature in Entity Framework 5.0 if I am using Database First. 回答1: Go to the model browser and create a new enum type, then go to whatever column you wish to use it on and change its type to the enum that you just created. 来源: https://stackoverflow.com/questions/11595008/enums-ef-5-0-database-first

Why does Database First EF skip mapping some tables?

给你一囗甜甜゛ 提交于 2019-12-12 11:31:02
问题 I'm using Entity Framework 4 and with a Database First binding, and EF is not generating the entities for a few of my tables. I'm not getting any errors, and no matter how many times I select the tables to generate from the "Update Model from Database" popup menu on the design surface, the same tables are still missing from the model. I get no errors in the wizard. They just don't get generated. Any clues? 回答1: EF requires a primary key on the table. EF will not map tables for which it can't

Add Function Import not available for function

血红的双手。 提交于 2019-12-12 11:12:12
问题 I've added a function in my database and I wanted it to be callable in my code. For stored procedures I've right clicked on the SP and selected Add Function Import in Model Browser to achieve this, but this option is not available for my function. What can I do to import the function? 回答1: Database functions are not available for Function import. Function import works only with stored procedures. You must manually create stub function and mark it with EdmFunction attribute for database

Represent View Without Key in Entity Framework

梦想与她 提交于 2019-12-11 16:28:00
问题 I'm using a model produced with Devart Entity Developer (.edml file, which I understand is mostly similar to .edmx) to generate Entity classes whose relations are initialized in a DbContext class. The database schema specifies no PK for View1, and all columns are nullable. But the code generation assumes that for views lacking a primary key, all columns are the key. I.e., the .ssdl has all columns under the Key element and the DbContext has .IsRequired() specified on all, like so: ssdl

EF: select all entities of subclass (inheritance)

梦想与她 提交于 2019-12-11 07:16:36
问题 I am using the Database first approach and DbContext. I have several inheritance structures (TPH) in my data model. But DbContext only creates one DbSet for the base class, and none for the subclasses. How should I retrieve all Entities of a specified subclass? I cannot write queries based on the mapping criteria, as i had to remove those fields from the data model. Can I simply add a new DbSet to the Entities class (partial class) ? 回答1: You can add new properties returning DbSet s of your

EF4 db-first: how to add missing relationships

情到浓时终转凉″ 提交于 2019-12-11 06:09:59
问题 I am using db-first to creating object model for a readonly database, but some relationships are not automatically picked up. For example in Foo.BarId is not automatically connected to Bar object. If I click on BarId property, I don't see anything to associate it to a Bar in the context menu or properties window. How can I manually claim foreign keys without messing up anything? 回答1: Figured out myself... here are the steps: (On model designer) Delete BarId property from Foo entity. Right

Entity Framework DbContext Connection string in app.config/web.config not being seen

与世无争的帅哥 提交于 2019-12-11 03:56:12
问题 So, I have followed this instruction from ADO.NET team blog to try to make a small test project. I have double-checked everything. It doesn't seem to work and keeps saying connection string is missing. http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx Step. 1 Build this UserModels.dll. In the dll, App.Config file, edmx generated this connection string: (hit the 'test' button when making it, and it connects successfully, and generated the edmx

MiniProfiler setup - A null was returned after calling the 'get_ProviderFactory' method

此生再无相见时 提交于 2019-12-11 03:54:51
问题 After hours of struggling with MiniProfiler to make it profile the Database queries, I have no luck and I'm getting the error: A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'StackExchange.Profiling.Data.ProfiledDbConnection'. The store provider might not be functioning correctly. I got through many SO posts but nothing has worked so far, like this post which is about the same error but with different configuration and well there's not