ef-code-first

The value's length for key 'data source' exceeds it's limit of '128'

社会主义新天地 提交于 2019-12-20 05:11:13
问题 I know that a very similar question has been asked here, but the answer didn't help me. I am using Entity Framework 6 with the Oracle.ManagerDataAccess.Client. If I define the connection string in app.config, then the connection works. If I specify the identical connection string in code, then I get the error The value's length for key 'data source' exceeds it's limit of '128'. which is correct. This is my connection string (with some names removed): "User Id=xxxxxxxxxxx;Password=xxxx;Data

How to expose Foreign Key property to existing entity having navigational property using EF6 Code First

谁说胖子不能爱 提交于 2019-12-20 04:52:32
问题 I have an entity which is already being used with an underlying database, and it was created with just the navigational property to an optional entity (1:0..1). So by default conventions, EF created a nullable foreign key column in the DB and gave it the "MyProp_Id" name with underscore, according to that convention. Now, I wish to expose that foreign key as a property on the entity, because it will make certain scenarios easier for me. I don't want to rename/change the underlying foreign key

Error Seeding Database, foreign key issue

不羁的心 提交于 2019-12-20 04:26:06
问题 I have built out my models using POCO. When I go to seed my database I get: Unable to determine the principal end of the 'CSP.Models.Type_Color' relationship. Multiple added entities may have the same primary key Here's the models in question: public class Type { [Key] [ScaffoldColumn(false)] public int TypeId { get; set; } [Required(ErrorMessage = "A Type Name is Required")] [Display(Name="Type")] public string Name { get; set; } public int ColorId { get; set; } public bool Other { get; set;

EF Reverse POCO against a SQL Database Project?

断了今生、忘了曾经 提交于 2019-12-20 03:31:12
问题 Can I use the EF Reverse POCO generator directly against a SQL Database Project? I keep my SQL database definition in a "Visual Studio SQL Database Project", which gives me some nice version control capabilities, schema comparison, and a few nifty deployment features. Sometimes I update the project files from a temporary database during development, but the version-controlled project is always the "truth" for any version. If I use the EntityFramework Reverse POCO Code First Generator, will I

Modifying a property on an entity in Entity Framework causes validation error

删除回忆录丶 提交于 2019-12-20 02:54:58
问题 I am trying to simply load an entity, modify a property and then save it back to the database. var db = new NewsletterContext(); var newsletter = db.Newsletters.Find(x => x.ID==newsletterID); newsletter.SomeProperty = 5; db.SaveChanges(); This causes a validation error as there are some properties on the newsletter object which are required and apparently not loaded when I do a Find() . I can solve this using an Include() for each required property followed by a Where() : var db = new

Entity Framework Code First Convert TPT to TPH

≡放荡痞女 提交于 2019-12-20 02:45:14
问题 I have developed an app (posts attachments, comments etc) using EF Code First using TPT. It works fine and is in beta testing with a number of clients., however there are a number of hierarchies. So I have a base model with various inherited models, each of which contain a number of properties which are themselves inherited types. I noticed it was very slow and so I looked in to the SQL it was generating and to get a list of posts, EF is generating over 2000 lines of SQL. The compilation time

Entity Framework 4.1 : The navigation property 'BusinessUser' declared on type 'Login' has been configured with conflicting multiplicities

我的未来我决定 提交于 2019-12-20 02:43:24
问题 I am having two entities BusinessUser { Id(PK), Name,...} Login { BusinessUserID(PK, FK), Email, Password, etc...} Relationship between BusinessUser and Login is one-to-zero/one . I am having following configurations In BusinessUser EF configuration class this.HasOptional(bu => bu.LoginInfo) .WithOptionalPrincipal(l => l.BusinessUser); In Login EF configuration class this.HasRequired(l => l.BusinessUser) .WithOptional(bu => bu.LoginInfo); I am getting following exception The navigation

EF Code first: Insert Many to many

我的未来我决定 提交于 2019-12-20 02:08:28
问题 A post can have many Topics. A topic can be assigned to many posts. When adding a post with two topics selected from topic list, two NULL topics also inserted to my topic table. See Id=34 and 35 . What did I do wrong? Topics should not be changed. I am adding a new post and selecting topics from fixed number of topics (a dropdownlist). It is keep tracked in PostTopics table (PostID, TopicID). Topics table: Id TopicName TopicDesc 31 Sports Sports 32 Game Game 33 Politics Politics 34 NULL NULL

EF Code first: Insert Many to many

蹲街弑〆低调 提交于 2019-12-20 02:07:43
问题 A post can have many Topics. A topic can be assigned to many posts. When adding a post with two topics selected from topic list, two NULL topics also inserted to my topic table. See Id=34 and 35 . What did I do wrong? Topics should not be changed. I am adding a new post and selecting topics from fixed number of topics (a dropdownlist). It is keep tracked in PostTopics table (PostID, TopicID). Topics table: Id TopicName TopicDesc 31 Sports Sports 32 Game Game 33 Politics Politics 34 NULL NULL

Manually add a migration?

孤街醉人 提交于 2019-12-20 02:05:53
问题 I've been using Entity framework code first in a project and all the tables have been created /modified a while ago. Now I need to add an unique constraint to a table. I want to create a migration which will have the following row in the Up() method. And there is no change on the model classes . CreateIndex("TableName", new[] { "Column1" }, true, "IX_UniqueKey"); And maybe the following row in the Down() DropIndex("TableName", new [] { "Column1" }); Can I just manually create a file under the