entity-framework-6

Entity framework many-to-many relation table created “backwards”

随声附和 提交于 2019-12-10 15:12:15
问题 I'm having an issue with EF6 and many-to-many relations. I have a following setup: public class Foo { public int Id { get; set; } public virtual ICollection<Bar> Bars { get; set; } public virtual ICollection<SubBar> SubBars { get; set; } public Foo() { Bars = new HashSet<Bar>(); SubBars = new HashSet<SubBar>(); } } public class Bar { public int Id { get; set; } public virtual ICollection<Foo> Foos { get; set; } public Bar() { Foos = new HashSet<Foo>(); } } public class SubBar { public int Id

Source Code for Entity framework 6.0.2

荒凉一梦 提交于 2019-12-10 14:37:43
问题 Why is there no source code history for entity framework: http://entityframework.codeplex.com/releases/view/114074 We can download and build the latest release 6.1 (alpha) which we dont want to do but we cannot download and build earlier releases 6.0.2 (stable) which we do want to do? Can anyone point me in the direction of finding that source code? 回答1: You can download source code directly from the Git repository. The revision 7648d33dfb53589d9c32b605c61758a5a6c0b80b is tagged with 6.0.2

How to delete a list of objects in EF6 when the object is detached from the context

拜拜、爱过 提交于 2019-12-10 14:24:07
问题 OK I can delete a single item in EF6 like this: public void DeleteUserGroup(MY_GROUPS ug) { using (var context = new MYConn()) { var entry = context.Entry(ug); if (entry.State == EntityState.Detached) { context.MY_GROUPS.Attach(ug); } context.MY_GROUPS.Remove(ug); context.SaveChanges(); } } If this method changed from passing a single instance of MY_GROUPS to a List<MY_GROUPS> how would I handle the delete? Would there be a more efficient way then just doing a foreach and setting the state

Replacement of Self-tracking entities in Entity Framework 6

蹲街弑〆低调 提交于 2019-12-10 14:03:11
问题 I am sure most of .NET developers must be facing this issue one way or the other. The problem is simple, I am upgrading my project from .NET 4 to .NET 4.5.1 . So far so good the upgrade went neatly. But when I upgraded from EF4 to EF6, I did encounter lot of bugs in my queries. Some of these were related to renaming the context which I did, but as for the errors related to Self-tracking entities , I am a little confused. Self-tracking entities are a major part of my project and EF6 not

Entity framework save changes

本秂侑毒 提交于 2019-12-10 13:14:51
问题 Is there a point to save changes after a read only action? The entities are loaded to cache, but nothing changes, should save changes be called before dispose? 回答1: From doc (DbContext.SaveChanges): Saves all changes made in this context to the underlying database. No there is no point in calling SaveChanges if you have not made any changes on your context. You can read more about this in detail here An entity can be in one of five states as defined by the EntityState enumeration. These

How to use the Procedure with User Defined Table Type in Entity Framework

冷暖自知 提交于 2019-12-10 13:09:39
问题 How to use a procedure with a user-defined table type in Entity Framework? I have the EF with database-first approach, when I add a procedure with a user-defined table type columns it will not reflected in the EF will update the model. And how can I pass the user-defined table parameter in EF with procedure? My procedure : Sample_Proce_Sp ( @TableTest @UserDefinedTable Readonly ) AS BEgin Select * from @TableTest END In EF I have updated the model, will adding the stored procedure it shows

Linq to entities extension method inner query (EF6)

倖福魔咒の 提交于 2019-12-10 13:05:20
问题 Can someone explain to me why the EF Engine is failing in the following scenario? It works fine with the following expression: var data = context.Programs .Select(d => new MyDataDto { ProgramId = d.ProgramId, ProgramName = d.ProgramName, ClientId = d.ClientId, Protocols = d.Protocols.Where(p => p.UserProtocols.Any(u => u.UserId == userId)) .Count(pr => pr.Programs.Any(pg => pg.ProgramId == d.ProgramId)) }) .ToList(); But if I encapsulate some into an extension method: public static IQueryable

Why DbSet<TEntity> doesn't implement EnumerableAsync

喜欢而已 提交于 2019-12-10 12:39:03
问题 In Entity framework 6.1.1 an IDbSet represents the collection of entities which can be queried from the database and its concrete implementation is DbSet as described in DbSet How come this interface or its concrete implementation doesn't contain any definition for ToEnumerableAsync or AsEnumerableAsync but ToListAsync,ToArrayAsync,ToDictionaryAsync? To give you an idea of why I came across this question I have the following piece of code which I wanted to make async: public IQueryable

The properties expression is not valid. The expression should represent a property

浪尽此生 提交于 2019-12-10 12:30:09
问题 I have these two entities public class Song : IPathHavingEntity { public int Id { get; set; } [Required] public string Path { get; set; } [Required] public virtual Album Album { get; set; } [Required] public int TrackNumber { get; set; } } public class Album : IPathHavingEntity { public int Id { get; set; } [Required] public string Path { get; set; } public virtual IEnumerable<Song> Songs { get; set; } [Required] public int AlbumNumber { get; set; } } Path is defined in the IPathHavingEntity

Iterate through linq query results by day to check conditions

馋奶兔 提交于 2019-12-10 12:14:41
问题 I have a query that returns a list of events in a date range. string EOOmessage = "";[enter image description here][2] string eventText = ""; DateTime js = DateTime.Now; DateTime je = DateTime.Now; var itCompareDay = (from h in db.DailyGPSTables where (h.EventDateTime >= startDate && h.EventDateTime <= endDate) select h).ToList(); I want to check the time for each event to make sure its in the proper sequence. For example JE(Job End) cannot be before JS(Job Start). I have tried many ways but