entity-framework-5

Entity Connection String Constructor not found in EF 5 and WCF 4.5 at runtime

ぐ巨炮叔叔 提交于 2019-12-08 07:34:19
问题 I have developed web application using VS 2010, WCF 4.0 and EF 4.1.1. My WCF Service developed with multiple EF Connection strings configured in web.config file those are taken from Entity Model app.config file. based on the parameters i am redirecting databases with EF Connection string at runtime. My WCF4.0 web.config like: <connectionStrings> <add name="WMSChennaiDEVEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data

EF 5 - Get foreign key value for navigation property

别来无恙 提交于 2019-12-08 07:08:59
问题 I want to get the foreign key value for a navigation property, without having to define the foreign key property (before the navigation property is loaded). Why? We cache (for instance) all "status"-objects application wide (yes we couldn't use enums for this). When we load an object with a navigation property to this status-class the repository will set the property to the cached item. I could go with a foreign key property, but since EF knows the key, I would like to get it from EF (maybe

Entity Framework - how to merge child collections? (Best Practices)

别等时光非礼了梦想. 提交于 2019-12-08 06:35:58
问题 Following is the exact scenario in my application. There are two entities: Customer: CustomerId, CustomerName CustomerAddress: AddressId, CustomerId (FK), Area, City A customer has one-to-many relation with CustomerAddress. A customer can have addresses of more than one cities. When I save changes to the existing customer - at that time, its underlying CustomerAddress collection will be having all addresses of one particular city only. So when I update that customer in the database, it should

ASP.NET MVC 4, Code First, View to Create/Edit Object with Many to Many Relationship

a 夏天 提交于 2019-12-08 05:50:52
问题 I have the model (code first) & database (SQL Server) setup with many to many relationship & seeding fine: A Place can have many tags (eg Restaurant, bar, cafe) - and tags can belong to many places. Place [ScaffoldColumn(false)] public virtual int PlaceID { get; set; } [Required(ErrorMessage = "Place Name is required")] [StringLength(100)] public virtual string Name { get; set; } [Required] public virtual string Address {get;set;} public virtual string ImageLogo {get;set;} public virtual

EF5 : Manual table mapping

强颜欢笑 提交于 2019-12-08 05:20:46
问题 How to do manual table mapping in Entity Framework 5 using the Code First approach? What I mean by table mapping is to associate a table name from the database to an entity class with a different name. 回答1: This is pretty simple. [Table("Foo")] public class Bar { // properties } 回答2: For fluent api: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<MyEntity>().ToTable("MyTargetTable"); } 来源: https://stackoverflow.com/questions/12957991/ef5-manual-table

Multiple foreign keys to the same parent table

蓝咒 提交于 2019-12-08 05:16:12
问题 I have the following simplified classes using EF 5 code-first, where my class B has multiple FK's pointing back to class A. public class A { public int Id {get;set;} ICollection<B> Bs {get;set;} } public class B { public int Id {get;set;} public int A1Id {get;set;} public int A2Id {get;set;} public int A3Id {get;set;} [ForeignKey("A1Id")] public A A1 {get;set;} [ForeignKey("A2Id")] public A A2 {get;set;} [ForeignKey("A3Id")] public A A3 {get;set;} } When I try to build my table I get this

In Entity Framework is there a cleaner way of converting an object type to a string representation for storage?

爱⌒轻易说出口 提交于 2019-12-08 04:13:02
问题 Very minor thing really but it bugs me slightly so I thought I'd ask. I have the POCO entity Setting and I'm using a code first approach to Entity Framework. public class Setting { [Required] [MaxLength(128)] public string Name { get; set; } [Required] public Type Type { get; set; } // Added to support the storing of Type in the database via Entity Framework. // Really would be nice to find a cleaner way but this isn't actually so bad. public string TypeString { get { return Type.ToString();

Entity Framework: Store entity property in json format

浪尽此生 提交于 2019-12-08 01:46:43
问题 Let's say you've an entity that has a property typed as ICollection<string> and I want to store it as varchar in SQL Server in JSON format. How to achieve this? Thank you in advance. 回答1: Probably You should have another string property in your Model class to hold the JSON represntation of the Collection of string. and that property will be mapped to your Table. Do not map the Collection property to your Table. Something like this public class Customer { public int ID { set;get;} public

.Net Entity Framework to CSV

浪尽此生 提交于 2019-12-08 01:26:06
问题 I'm using the latest Entity Framework with DBContext. I have a result set that I want to convert to comma separated values. I've done something similar with DataTables in VB DataTable to CSV extraction. I've got the QuoteName method working. I've also get a derivative of the GetCSV method working using a foreach. The problem is that it is a lot slower than the comparable code for a DataTable. So I'm hoping someone will have some suggestions. public static string GetCSV(this IQueryable entity)

How do I create a primary key using two foreign keys in Entity Framework 5 code first?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 18:06:45
问题 I have an entity where the primary key consists of two foreign keys to two other tables. I have the configuration working with the following but the table is generated with two FK references. The table: domain.Entity1 MorePK (PK, FK, int, not null) Entity2_Id (PK, FK, int, not null) Entity3_Id (PK, FK, int, not null) OtherData (varchar, null) Entity2_Id1 (FK, int, null) Entity3_Id1 (FK, int, null) is generated from: public Entity1 { public int MorePK { get; set; } public int Entity2_Id { get;