entity-framework-4

Entity framework Invalid Column name, EF adds numer 1 to primary key

旧街凉风 提交于 2020-01-11 04:50:06
问题 I have these two entities: public partial class Suscriptores { public Suscriptores() { this.Publicacion = new HashSet<Publicacion>(); } [Key] public int IdSuscriptor { get; set; } public string LogoSuscriptor { get; set; } public string Identificacion { get; set; } public string Nombre { get; set; } public string Direccion { get; set; } public string Telefono { get; set; } public string Email { get; set; } public string Fax { get; set; } public string Home { get; set; } public virtual

Cannot insert duplicate key in object 'dbo.User'.\r\nThe statement has been terminated

杀马特。学长 韩版系。学妹 提交于 2020-01-10 09:51:27
问题 I have a user table. there are references to this table from other tables for fields such as CreatedBy. Problem is, when I am inserting a row of another table (say 'x'), it tries to insert a new user into the user table. What it should be doing is insert a row into table 'x' with CreatedBy as the existing user. Using Entity Framework 4. Anyone faced a problem like that before? 回答1: You can insert an entity together with related entities or you can insert an entity without the related entities

Use the ColumnAttribute or the HasKey method to specify an order for composite primary keys

大憨熊 提交于 2020-01-10 07:52:21
问题 I'm trying to use composite primary key on 2 objects with parent-child relationship. Whenever I try to create a new migration, I get an error: Unable to determine composite primary key ordering for type 'Models.UserProjectRole'. Use the ColumnAttribute or the HasKey method to specify an order for composite primary keys. As per error suggests, I do add annotation Column (Order = X) but the error still there and does not go away, unless I leave only one field with Key annotation. Here is my

How can I upgrade my Sql Server CE 3.5 sdf database to Sql Server CE 4.0?

戏子无情 提交于 2020-01-10 07:51:22
问题 I need to update my SqlCE3.5 database to 4.0. I get the following error message when I'm trying to access my 3.5 sdf/database using the new CE4.0 connection provide :- System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlServerCe.SqlCeInvalidDatabaseFormatException: The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method . Anyone know how I can do this? Obviously I need to do it

Can I mix Table per Hierarchy and Table per Type in Entity Framework?

本小妞迷上赌 提交于 2020-01-09 08:08:06
问题 Say I have 2 tables: Message and SuperMessage and 3 entities: Message (base (not abstract)), Comment (inherits from Message) and SuperMessage (inherits from Message) Message has a non-nullable MessageType field which is used as a discriminator. MessageType = 1 means it is a Message MessageType = 2 means it is a Comment MessageType = 3 AND and join to the SuperMessage means it is a SuperMessage The problem is that I cannot specify a condition on MessageType of the SuperMessage's Mapping

Entity Framework 4 / Linq: How to convert from DateTime to string in a query?

早过忘川 提交于 2020-01-09 07:15:16
问题 I have the following query: from a in Products select new ProductVM { id = a.id, modified = a.modified.ToString() } Which gives me an error of: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression. The modified in the Products table is DateTime. The modified in the ProductVM class is string. Any ideas? This has to be a trivial issue. 回答1: ToString() is not supported in Linq to Entities - there is a list

Entity Framework 4 / Linq: How to convert from DateTime to string in a query?

别来无恙 提交于 2020-01-09 07:13:10
问题 I have the following query: from a in Products select new ProductVM { id = a.id, modified = a.modified.ToString() } Which gives me an error of: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression. The modified in the Products table is DateTime. The modified in the ProductVM class is string. Any ideas? This has to be a trivial issue. 回答1: ToString() is not supported in Linq to Entities - there is a list

Is DbContext the same as DataContext?

无人久伴 提交于 2020-01-08 19:39:35
问题 I'm following a tutorial by Scott Gu that refers to a class named DbContext. I can't find it on any namespace on framework 4 and it seems to me it was renamed from CT4 DbContext to .net4 System.Data.Linq.DataContext. Is my assumption correct? 回答1: DbContext is a new class that was added in the recent separate download by EF team. It is currently not part of the core EF 4.0. However DbContext moving forward would be the preferred way to interact with EF. So how is it different from

Get TraceString for your business objects in the Entity Framework

☆樱花仙子☆ 提交于 2020-01-07 04:44:28
问题 How do I get the trace string for a query like this: var product = _context.Products.Where( p => p.Category == "Windows" ) .SingleOrDefault(); // I can't do this since product is not an ObjectQuery instance // product.ToTraceString(); 回答1: Different answer for different problem. You can't call ToTraceString() on this: var product = _context.Products.Where( p => p.Category == "Windows" ) .SingleOrDefault(); You can do this: var q = _context.Products.Where( p => p.Category == "Windows" ) var ts

Generating Entity Framework based on Views: Nullable types

半腔热情 提交于 2020-01-07 04:30:27
问题 Some of the properties in a class generated by EF are nullable, and some arent. My first instinct was that this should be driven by Nullable property returned by sp_help MyView. But that doesn't seem to be the case. Some of my types that are returned as Nullable by sp_help get generated as Nullable , while others, get generated as just bool instead of Nullable*bool* what is it driven by, and is there any way to control it by the view? as a test i created ViewA and than ViewB which selected