entity-framework

Polymorphic cross-associations on Entity Framework

喜夏-厌秋 提交于 2020-01-14 11:07:28
问题 OK, this is an interesting and most importably real urgent problem for me to solve... In order for others to neatly comprehend it, I've stretched myself to make a well illustrated post. The Object Model So I have this simple, easy and "beautiful" model in mind. See the first picture. (You can ignore PathEntry , it's not relevant in my situation.) The idea is that a MediaFeedItem owns: a collection of ThumbnailFileEntries (accesible through the ThumbnailFiles property) at most 1 raw FileEntry

How to set connection in Entity Framework 6 using Code-Based Configuration

蓝咒 提交于 2020-01-14 10:34:08
问题 I'm a bit confused by the (sparse) MSDN documentation on EF6 code-based configuration. I have a WPF application that needs to create an SQL connection based on command-line parameters and/or user input from a dialog. In older versions of EF I accomplished this by building the connection string and passing it to my derived DbContext every time. It would be nice if I could avoid having to do that, since it also means having to pass the connection string to every view model that needs to use the

Entity Framework ISNULL in Where condition

落爺英雄遲暮 提交于 2020-01-14 10:27:06
问题 I have a Query in SQL Server : SELECT * FROM MyTable t WHERE ISNULL(t.Status,'') = '' How I can do it in Entity Framework? EDIT: Oh Sorry my code was like WHERE ISNULL(t.Status,'') = '' 回答1: Try something like MyTable.Where( t => (t.Status ?? "") == "CO" ) 回答2: Although the question is ok, the logic isn't sound. Because if a value is equal to CO , it can never be equal to either NULL or '' . In this case you could just easily call it like this: SQL: SELECT * FROM MyTable t WHERE t.Status =

Entity Framework and string as NCLOB on oracle Db

倖福魔咒の 提交于 2020-01-14 10:03:15
问题 I have this model: public class Teacher { public int TeacherID { get; set; } public string Name { get; set: } public string Surname{ get; set; } } and when Model First run, it creates my Teachers table and DbSet, but for Name and Surname (which are string) it assigns NCLOB type to the column. Now, with NCLOB type I cannot do some operations like equals or distincts on my table.... How can I force MF to set columntype to varchar? 回答1: I've managed to solve the issue setting the maximum string

Migrate entity with updated DatabaseGeneratedOption in Entity-Framework

僤鯓⒐⒋嵵緔 提交于 2020-01-14 09:52:10
问题 I have created code-first app according to this article - Code First to a New Database. Now I am going to change DatabaseGeneratedOption for Blog.BlogId . I changed my code in next way: public class Blog { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int BlogId { get;set; } ... } And created migration for this code update: public override void Up() { DropForeignKey("dbo.Posts", "BlogId", "dbo.Blogs"); DropPrimaryKey("dbo.Blogs"); AlterColumn("dbo.Blogs", "BlogId", c => c.Int

Migrate entity with updated DatabaseGeneratedOption in Entity-Framework

为君一笑 提交于 2020-01-14 09:52:08
问题 I have created code-first app according to this article - Code First to a New Database. Now I am going to change DatabaseGeneratedOption for Blog.BlogId . I changed my code in next way: public class Blog { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int BlogId { get;set; } ... } And created migration for this code update: public override void Up() { DropForeignKey("dbo.Posts", "BlogId", "dbo.Blogs"); DropPrimaryKey("dbo.Blogs"); AlterColumn("dbo.Blogs", "BlogId", c => c.Int

Visual Studio 2015 EDMX model browser and diagram is missing

≯℡__Kan透↙ 提交于 2020-01-14 09:50:34
问题 I have recently updated to Visual Studio 2015. Opened up my solution and works. Till I decided to add in an entity to my edmx. So I double-clicked on the edmx file to open the diagram like it should or maybe the model browser at least but it only opens an XML page. I checked any missed installation from the setup but didn't find anything about entity framework there. I tried to create a test solution and create another edmx but ADO.NET entity is missing as well. What is going on? Am I going

Why am I getting “The magic number in GZip header is not correct.” error using OWIN auth against Azure SQL

送分小仙女□ 提交于 2020-01-14 09:39:30
问题 Nothing on Google or SO relates to this specific problem, so asking a new question. I created a brand new Asp.Net MVC Web Application with the standard user-security option. I also created an empty database in Azure. I did nothing but change the default connection string to this: <connectionStrings> <add name="DefaultConnection" connectionString="data source=mydatabase.database.windows.net;initial catalog=Feedback;persist security info=True;user id=LeaveFeedbackuser;password=mypassword

Many to many relationship detecting changes

荒凉一梦 提交于 2020-01-14 09:23:31
问题 I am trying to understand why DbContext doesn't detect changesin many-to-many relationship. This is what I have set in model configuration: this.Configuration.ValidateOnSaveEnabled = false; this.Configuration.ProxyCreationEnabled = false; this.Configuration.LazyLoadingEnabled = false; This is the test code: var book = Context.Set<Book>().Where(b => b.Id == 1).Single(); var author = Context.Set<Author>().Where(a => a.Id == 2).Single(); book.Authors.Add(author); if I check for changes, it doesn

Many to many relationship detecting changes

做~自己de王妃 提交于 2020-01-14 09:23:29
问题 I am trying to understand why DbContext doesn't detect changesin many-to-many relationship. This is what I have set in model configuration: this.Configuration.ValidateOnSaveEnabled = false; this.Configuration.ProxyCreationEnabled = false; this.Configuration.LazyLoadingEnabled = false; This is the test code: var book = Context.Set<Book>().Where(b => b.Id == 1).Single(); var author = Context.Set<Author>().Where(a => a.Id == 2).Single(); book.Authors.Add(author); if I check for changes, it doesn