entity-framework

Scaffolding EntityFramework 6 Unable to cast object of type 'System.Data.Entity.Core.Objects.ObjectContext' to 'System.Data.Objects.ObjectContext'

狂风中的少年 提交于 2020-01-12 03:40:09
问题 I wanna use Scaffolding in EntityFrameWork 6, but get this: Unable to retrieve metadata for '[myNameSpace].Models.prod'. Unable to cast object of type 'System.Data.Entity.Core.Objects.ObjectContext' to type 'System.Data.Objects.ObjectContext'. Does EF 6 support scaffolding? Update After some while, microsoft realease new upgrade for support scafolding and some others features I think it doesn't work while you upgrade vs IDE to 2013 回答1: I'm sorry but it is not supported ASP.NET MVC 4

Unit test Entity Framework using moq

巧了我就是萌 提交于 2020-01-12 03:26:18
问题 I'm using entity framework and trying to unit test my data services which are using EF. I'm not using repository and unit of work patterns. I tried the following approach to mock the context and DbSet: private static Mock<IEFModel> context; private static Mock<IDbSet<CountryCode>> idbSet; [ClassInitialize] public static void Initialize(TestContext testContext) { context = new Mock<IEFModel>(); idbSet = new Mock<IDbSet<CountryCode>>(); context.Setup(c => c.CountryCodes).Returns(idbSet.Object);

Get all tracked entities from a DbContext?

人盡茶涼 提交于 2020-01-12 01:45:47
问题 Many of the tables in my database need to have a "DateCreated" and "DateModified" column. I want to update these columns whenever SaveChanges() is called. All my model objects inherit from a class AbstractModel to allow this kind of behavior. The class looks like this: public abstract class AbstractModel { public virtual void UpdateDates() { } } I then plan to override UpdateDates() in any child classes that have DateCreated and DateModified fields they need to maintain. To use this, I need

Multiple condition linq

混江龙づ霸主 提交于 2020-01-11 14:43:24
问题 I am using linq in my application. Query has several conditions .Where(a => !one || a.id == 1) . bool one = false; bool two = false; bool three = false; db.type.Where(w => !one|| w.id == 1).Where(w => !two || w.id == 2).Where(w => !three || w.id == 3).ToList() But this query give me result: db.type.Where(w => w.id == 1 && w.id == 2 && w.id == 3) I want to get: db.type.Where(w => w.id == 1 || w.id == 2 || w.id == 3) Help me please. How I can this fix? 回答1: If you need to or the ids in your

Generate Dynamic Linq query using outerIt

我与影子孤独终老i 提交于 2020-01-11 13:14:56
问题 I am using Microsoft's Dynamic Linq (System.Linq.Dynamic) library to generate some queries at run time. This has worked great for me, but for one specific scenario. Simplified scenario - I am trying to query all claims which have some specific tags that the user has selected and whose Balance is greater than some number. static void Main(string[] args) { var claims = new List<Claim>(); claims.Add(new Claim { Balance = 100, Tags = new List<string> { "Blah", "Blah Blah" } }); claims.Add(new

.Include in following query does not include really

馋奶兔 提交于 2020-01-11 12:26:10
问题 var diaryEntries = (from entry in repository.GetQuery<OnlineDiary.Internal.Model.DiaryEntry>() .Include("DiaryEntryGradeChangeLog") .Include("DiaryEntryAction") join diary in repository.GetQuery<OnlineDiary.Internal.Model.OnlineDiary>() on entry.DiaryId equals diary.Id group entry by diary into diaryEntriesGroup select new { Diary = diaryEntriesGroup.Key, DiaryEntry = diaryEntriesGroup.OrderByDescending(diaryEntry => diaryEntry.DateModified).FirstOrDefault(), }); This query does not include

Map tables relationship from legacy database w/ entity framework with only primary keys

Deadly 提交于 2020-01-11 12:14:29
问题 data (table name) dataid PK, value1, value2, value3 data_address (table name) dataaddressid PK, dataid - id to errenddataid, addressid1 - id to en addressid, addressid2 - id to en addressid, type address (table namne) addressid PK - id to addressid1 or addressid2, address1, address2, name, zipcode, city I have a really hard time trying to map this relations using Entity Framework 5, if some one have an idea or good links I would much appreciate that! 回答1: If you are certain that the database

Map tables relationship from legacy database w/ entity framework with only primary keys

回眸只為那壹抹淺笑 提交于 2020-01-11 12:13:51
问题 data (table name) dataid PK, value1, value2, value3 data_address (table name) dataaddressid PK, dataid - id to errenddataid, addressid1 - id to en addressid, addressid2 - id to en addressid, type address (table namne) addressid PK - id to addressid1 or addressid2, address1, address2, name, zipcode, city I have a really hard time trying to map this relations using Entity Framework 5, if some one have an idea or good links I would much appreciate that! 回答1: If you are certain that the database

Entity Framework Code First and Classes that Implement IList<T>

谁说我不能喝 提交于 2020-01-11 12:09:10
问题 I have a ComplexType that must implement IList<T> (background info here). Unfortunately, Entity Framework complains about the indexed property required of that interface [NotMapped] public T this[int index] (Note it's decorated with the NotMapped data annotation). I get a DbUpdateException at runtime with the inner exception Indexed properties are not supported. If I comment out that the class implements IList<T> and comment out the indexed property, instances of the class persist as expected

Entity Framework Code First and Classes that Implement IList<T>

泄露秘密 提交于 2020-01-11 12:09:05
问题 I have a ComplexType that must implement IList<T> (background info here). Unfortunately, Entity Framework complains about the indexed property required of that interface [NotMapped] public T this[int index] (Note it's decorated with the NotMapped data annotation). I get a DbUpdateException at runtime with the inner exception Indexed properties are not supported. If I comment out that the class implements IList<T> and comment out the indexed property, instances of the class persist as expected