ef-code-first

Entity framework creating a non existent column in the query

落爺英雄遲暮 提交于 2019-12-11 02:35:17
问题 This has been puzzling me for quite some time but I keep getting an invalid identifier error when my entity framework tries to execute an oracle query. The classes in question are the following: public class Projectship : ModelTrackingBase { [Column("PROJECTID")] public long ProjectId { get; set; } [Column("VISITID")] public long VisitId { get; set; } public virtual Bpid Bpid { get; set; } //new public virtual Visit Visit { get; set; } } and public class Bpid : EntityIdBase { [Column(

Use string as type of DbSet like DbSet<string> in EF-CodeFirst

最后都变了- 提交于 2019-12-11 02:33:47
问题 I want to have a list of string and save and load them to/from database using EF-CodeFirst. this is my DbContext class: public class KeysDbContext : DbContext { public DbSet<string> Keys { get; set; } } but when I try to run the code I get this exception: System.InvalidOperationException : The type 'System.String' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class,

Add entity in many to many relationship in Entity Framework

爱⌒轻易说出口 提交于 2019-12-11 02:24:58
问题 I have a many to many relationship in my code first. public class Post { public int Id { get; set; } public ICollection<Tag> Tags { get; set; } } public class Tag { public int Id { get; set; } public ICollection<Post> Posts { get; set; } } modelBuilder.Entity<Post>().HasMany(c => c.Tags).WithMany(a => a.Posts); If i have a PostId and a TagId , How i can insert relationship with single query in entity framework (Without load Post or Tag and add relationship to that) 回答1: This is one of the

EF ObjectQuery<T> Context, Parameters, Connection properties equivalent on DbSet<T>

五迷三道 提交于 2019-12-11 02:09:54
问题 In the earlier versions of Entity Framework, we were able to reach the Context out of ObjectQuery in order to read Parameters , Connection , etc. as below: var query = (ObjectQuery<T>)source; cmd.Connection = (SqlConnection)((EntityConnection)query.Context.Connection).StoreConnection; cmd.Parameters.AddRange( query.Parameters.Select(x => new SqlParameter( x.Name, x.Value ?? DBNull.Value) ).ToArray() ); When I look at the DbSet<T> object, I am unable to find any equivalent of this. My purpose

Proper pattern to handle one-to-many with different related entities

牧云@^-^@ 提交于 2019-12-11 02:04:26
问题 I have a C# project and I use Entity Framework as the ORM. I have a User , which is able to pay to many banks. Each bank is a separate entity and each one of them is described by different fields. The problem is - one User can have no-or-many different Bank s. I'm not really sure how to model this - the temporary solution was to add an additional UserBank entity, which is in 1:1 realtionship with User . The classes look (more or less) like that: public class User { public virtual UserBank

Serialize EF Proxy when POCO has IsReference = true Attribute

北慕城南 提交于 2019-12-11 01:58:02
问题 How can I serialize an Entity Framework Code First Proxy when the class it is proxying is decorated with DataContractAttribute(IsReference = true) ? When using DataContractSerializer with ProxyContractResolver, I get the following: The IsReference setting for type 'System.Data.Entity.DynamicProxies.MyType_59A83378572C10D0B31B6892FB6C3E7428C4BA214322C7A77BD5E1EB19E529CA' is 'False', but the same setting for its parent class 'My.Namespace.MyType' is 'True'. Derived types must have the same

Entity Framework Code First Migrations and Firebird

痴心易碎 提交于 2019-12-11 01:48:16
问题 I'm trying to enable migrations on a Firebird 2.5 database. I'm using VS2015 and the ADO Driver and Entity Provider are installed and working correctly. I reverse engineered the database, made the necessary changes to make it work. I can do the enable-migrations on the Package Manager Console, and add a migration. When I do update-database this happens: PM> update-database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Applying explicit migrations

EF Code first Eager loading and OrderBy problem

╄→尐↘猪︶ㄣ 提交于 2019-12-11 01:43:35
问题 I have two entities called Category and Product with 1:n relation. I want to get a Category with its childs that childs be in order. This is my linq: _db.Categories.Where(c => c.CategoryID == catID) .Include(c => c.Products.OrderBy(p => p.ProductID)) .SingleOrDefault(); This query enforce with the below exception because of orderby. The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator

Domain Modeling and Mapping with EF CPT5

百般思念 提交于 2019-12-11 01:37:31
问题 I am trying to model out a album that has a collection of photos. Each Album will have a collection of Photos and a Photo that is a thumb. This is what I have but EF does not seem to like it. I am using EF CPT5 The Model : public class Album : IEntity { private DateTime _dateCreated; public Album() { _dateCreated = SystemTime.Now(); Photos = new List<Photo>(); } public long Id { get; set; } public string Name { get; set; } public string Location { get; set; } public DateTime DateCreated { get

make EF map byte array to binary instead of varbinary

你说的曾经没有我的故事 提交于 2019-12-11 01:29:48
问题 By default c# data type byte[] in POCO object is mapped to sql type varbinary. Is it possible to map it to binary type using dataannotations or fluent API? Thanx. 回答1: I have found the answer myself. It can be done using Fluent API the following way protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<MyEntity>().Property(x => x.BinaryProperty).HasMaxLength(LengthOfBinaryField).IsFixedLength(); } 来源: https:/