entity-framework-4.1

Copy a property that is an IDbSet<T> to a property on another class that is a List<T> with the same names using reflection?

淺唱寂寞╮ 提交于 2019-12-23 17:19:27
问题 We have a scenario in our unit tests where we have created a FakeDbSet that implements IDbSet. In a FakeUnitOfwork I have properties that are IDbSets and getting new-ed up using the FakeDbSet. Without having to write out each different property in my Commit method I am trying to use reflection to iterate over the properties inside the FakeUnitOfWork. I then want to copy the property values to a differnt class that has propertes of List<> of the same type. So I may have a property in my

Cannot rename Discriminator column in Entity Framework 4.1 Code First database

前提是你 提交于 2019-12-23 16:26:14
问题 I have a model hierarchy configuration like so: [Table("A")] abstract class A { } class B : A { } // treated as abstract [Table("C")] class C : B { } This results in a TPH for A and B, and a TPT for C. So far this seems to work fine. There are two database tables being generated: "A" which contains both A and B model records, and "C" which contains only C model record columns not already kept in table "A". For the TPH arrangement on Table A, there is a generated "Discriminator" column, which

EF Data Migrations does not work after close project

天涯浪子 提交于 2019-12-23 12:40:25
问题 i'm using entity framework data migrations. if i change something about entites or something else, i try to use " add-migration MyFirstMigration " on Package Manager Console. But it returns an exception : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was inclu ded, verify that the path is correct and try again. At line:1 char:14 + add-migration <<<< + CategoryInfo : ObjectNotFound:

Two same class types in entity framework class issue

杀马特。学长 韩版系。学妹 提交于 2019-12-23 11:23:28
问题 I am implementing feature that allows users to follow each other. I have database tables: User{UserId, FirstName, LastName etc.} Followings{FollowerUserId, FollowingUserId, CreatedOnDate etc.} So I added EF class: public class Follow { [Key, Column(Order = 1)] public Guid FollowerUserId { get; set; } [Key, Column(Order = 2)] public Guid FollowUserId { get; set; } public DateTime CreatedOnDate { get; set; } public virtual User Follower { get; set; } public virtual User Following { get; set; }

Two same class types in entity framework class issue

天大地大妈咪最大 提交于 2019-12-23 11:22:10
问题 I am implementing feature that allows users to follow each other. I have database tables: User{UserId, FirstName, LastName etc.} Followings{FollowerUserId, FollowingUserId, CreatedOnDate etc.} So I added EF class: public class Follow { [Key, Column(Order = 1)] public Guid FollowerUserId { get; set; } [Key, Column(Order = 2)] public Guid FollowUserId { get; set; } public DateTime CreatedOnDate { get; set; } public virtual User Follower { get; set; } public virtual User Following { get; set; }

A column ID occurred more than once in the specification?

扶醉桌前 提交于 2019-12-23 09:14:40
问题 I am getting this error message when using EF 4.1 code first approach with Sql compact 4. I don't see any model who has id column more than one so i have no idea why this error occured. What can cause this error ? Edit : I want to specifiy few extra things. Database creating is success but model creating is not. And Exception has been thrown from sqlce methods. 回答1: This issue stems from a SQL query that returns two or more columns that have an identical name. SQL will handle exact duplicate

Custom SQL functions and Code First (EF 4.1)

不打扰是莪最后的温柔 提交于 2019-12-23 07:49:19
问题 I'm using Entity Framework 4.1 RC and code first approach. How can I call custom SQL functions? If I use EdmFunction attribute, what namespace should I specify? [EdmFunction("Namespace", "GetAge")] public static int GetAge(Person p) { throw new NotSupportedException(…); } When I try to execute a LINQ query with such function the following exception is thrown: The specified method '...' on the type '...' cannot be translated into a LINQ to Entities store expression. 回答1: If you want to call

How to change/set collation in EF Code first

老子叫甜甜 提交于 2019-12-23 07:38:25
问题 I want to change Collation of the whole database created by ef code first, I try to do it by running a script after creation but it does not works, _dbContext.Database.Delete(); _dbContext.Database.CreateIfNotExists(); _dbContext.Database.ExecuteSqlCommand("ALTER DATABASE afi COLLATE French_CI_AI"); Is it possible to set the collation before creating the database? That is the exception I get : Resetting the connection results in a different state than the initial login. The login fails. Login

Can't Translate Extension Method Into Store Expression

喜你入骨 提交于 2019-12-23 05:13:36
问题 I have an extension method as follows: public static bool SatisfiesSomeCondition(this Post post, SomeObj someObj) { return post.SomeObjId == someObj.SomeObjId; } And i'm trying to use it like this: var query = ctx.Posts.Where(p => p.SatisfiesSomeCondition(someObj)).ToList(); But i get the error: LINQ to Entities does not recognize the method 'Boolean SatisfiesSomeCondition(xx.xx.xx.Post, xx.xx.xx.SomeObj)' method, and this method cannot be translated into a store expression. If i change the

Error comes as a {“Invalid object name 'dbo.TableName'.”}

。_饼干妹妹 提交于 2019-12-23 04:45:50
问题 I'm using Entity Framework and MVC3, I have used Model First approch... I have used Company as a Base class and I have inherited the Lead Class from it. When I run the application its gives an error... This is Base Class using System; using System.Collections.Generic; namespace CRMEntities { public partial class Company { public int Id { get; set; } } } This is Lead Class (Child) using System; using System.Collections.Generic; namespace CRMEntities { public partial class Lead : Company {