ef-model-first

ObjectContext public in debug mode, internal in release mode

折月煮酒 提交于 2020-02-06 02:51:34
问题 Is there an easy way to make an ObjectContext public in debug mode and internal in release mode? With Linqpad it is very convenient to connect to an ObjectContext for quick testing and querying, so for development purposes I want it to be public. But I don't want to think of the consequences when the same convenience is deployed to some smart customer. 回答1: As mentioned in the comment, this may not be of any practical use, but: #if DEBUG public #endif class YourContext : ObjectContext { ... }

ObjectContext public in debug mode, internal in release mode

北城以北 提交于 2020-02-06 02:51:09
问题 Is there an easy way to make an ObjectContext public in debug mode and internal in release mode? With Linqpad it is very convenient to connect to an ObjectContext for quick testing and querying, so for development purposes I want it to be public. But I don't want to think of the consequences when the same convenience is deployed to some smart customer. 回答1: As mentioned in the comment, this may not be of any practical use, but: #if DEBUG public #endif class YourContext : ObjectContext { ... }

EF “Model First”: Create entity in edmx and db-table from class?

孤街浪徒 提交于 2020-01-16 05:26:17
问题 This question is part of my following one I already asked roughly 2.5 years ago: Entity Framework (.NET) Round-Trip Modelling with Model First? I wanted to ask if in the meantime, the following is possible (and from which version of EF upwards): We are currently using EF 5.0 with the "Model First" approach (VS 2012). After first problems, we managed to configure the two T4 templates for generating the DbContext-derived class and the POCOs so that if we need to map a new (or existing) database

Map a column to be IDENTITY in db

戏子无情 提交于 2020-01-05 16:32:42
问题 Although I have marked my ID column with .Identity() , the generated database schema doesn't have IDENTITY set to true, which gives me problems when I'm adding records. If I manually edit the database schema (in SQL Management Studio) to have the Id column marked IDENTITY , everything works as I want it - I just can't make EF do that by itself. This is my complete mapping: public class EntryConfiguration : EntityConfiguration<Entry> { public EntryConfiguration() { Property(e => e.Id)

How to run an SQL script against a MDF file?

别来无恙 提交于 2020-01-03 09:25:14
问题 I've created a database model with model-first method using Entity Framework 4.0. I then created an sql script using the Generate Database from Model... I've also created an SQL Server Database file in my App_Data folder. How do I now run the SQL file against this MDF file? I'm using Visual Studio 2010. 回答1: I ran into this same problem and here is what worked for me. When I selected "Generate Database from Model..." I created a new MDF file. This process worked fine and Visual Studio

How to call Database.SetInitializer on model-first?

假如想象 提交于 2020-01-02 06:31:29
问题 I created a model in the edm designer (VS10) using "DbContext Entity Generator" as the generation item. In the generated DbContext subclass, it overrode the constructor so I can't use it in the other partial class: public EntitiesContainer() : base("name=EntitiesContainer") { this.Configuration.LazyLoadingEnabled = false; } What's the proper way of initialize a database with model-first? 回答1: You could alter the T4 template that's being used for generating the DbContxt class. Then you could

1:1 relationship problems with EF Model First

眉间皱痕 提交于 2019-12-31 03:51:07
问题 I'm trying to develop an application as Model-First with EF. I tried everything to accomplish a table-splitting pattern and a 1:1 relationship but looks like EF just doesn't let me. Assuming I do use Model-First - is there a way to put a 1:1 relationship without messing with the generated files and EF giving that annoying: Multiplicity is not valid in Role 'Blablalah' in relationship 'Blabalbala'. Because the Dependent Role properties are not the key properties, the upper bound of the

Add index in EF Model First design

你离开我真会死。 提交于 2019-12-29 05:27:45
问题 I like the option of doing model first design with the Entity Framework (4). However, I haven't been able to find out how to add an additional index to a table besides the primary key. Is this possible in the visual designer? Or do you need to add an index manually after creating the database (which would be a shortcoming of the designer)? 回答1: Read this article. Section Influencing the DDL Generation . HTH 来源: https://stackoverflow.com/questions/3333674/add-index-in-ef-model-first-design

Remove auto generate comments

不羁的心 提交于 2019-12-24 00:13:30
问题 I create some classes using Model First, EF4x as you can see a similar example in this answer from algreat. My question is about the default comments that are generate as it shows in the block-quote below //------------------------------------------------------------------------------ // <auto-generated> // This code was generated from a template. // // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code

Mapping Boolean property to Oracle using Entity Framework

旧巷老猫 提交于 2019-12-23 10:39:28
问题 I need to connect a system to oracle using entity model first. I have a model with the entity "Entity1". "MyBool", as the name says, it's a boolean property. I sucessfully generated the sql script from the model and run it on oracle database. Then I have this code: static void Main(string[] args) { Model1Container context = new Model1Container(); Entity1 entity = context.Entity1.FirstOrDefault(); } This code throws this exception: Schema specified is not valid. Errors: Model1.msl(8,12) :