entity-framework-5

Entity Framework is not returning the proper data. It is repeating data from a single record

匆匆过客 提交于 2019-12-12 03:57:32
问题 Using MVC 4 with EF code First. When doing linq to EF selects statements, the collections are being populated with what seems like the last record's data. And what's weirder, only some of the properties are repeated where others are not. It is best to show you by example: Using this query returns the proper data: var orders = db.Orders.ToList(); OrderID OrderTotal Name 1 215.00 Bob 2 415.00 Mark 3 315.50 Ralph When I filter the Orders entity by a SubscriberID, which is a foreign key, like so:

The specified type member is not supported in LINQ to Entities. entity members, and entity navigation

最后都变了- 提交于 2019-12-12 03:54:39
问题 public partial class User : IUser { public long ID {get; set;} public BaseUser BaseUser { get { var context = new Factory().Create<ContextDB>(); return context.Users.Find(this.ID); } } } and var result = _Context.Employees.Where(t => t.User.BaseUser.UserName.ToLower().Trim().Contains(searchKey)); Here I am getting an exception: The specified type member 'BaseUser' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Any

Breeze webapi controller 'cannot support querying' over DbSet error

二次信任 提交于 2019-12-12 03:33:28
问题 I have setup very similar to breeze sample application which comes in sample nuget. This is the code of my api controller: [JsonFormatter, ODataActionFilter] public class WorkOrdersController : ApiController { readonly EFContextProvider<WorkOrdersContext> _contextProvider = new EFContextProvider<WorkOrdersContext>(); public WorkOrdersController() { // I was thinking this may be the cause of the issue this._contextProvider.Context.Configuration.ProxyCreationEnabled = false; } [HttpGet] public

Dynamic predicate building in EF5

拜拜、爱过 提交于 2019-12-12 03:08:48
问题 Ok, I have to build a predicate to select an unknown number of columns from a known entity in EF5 AND filter by an unknown number of columns ONE of which will always be a name from a child collection. So this is what I need to end up with var q = db.Set<Entity>() .Where(e => e.Code.Contains("q") || e.Translations.FirstOrDefault(t => t.Culture.ID == "whatever").Description.Contains("q")) .Select(e => new { e.ID, e.Code, Name = e.Translations.FirstOrDefault(t => t.Culture.ID == "whatever")

How do you execute native SQL using Entity Framework when using the DataContext through an Interface

 ̄綄美尐妖づ 提交于 2019-12-12 03:03:12
问题 SETUP Ok so I have an application that follows the Onion archetecture approach i.e: Frontend References > Services and Domain Service References > Domain and Data Data References > Domain Domain References > nothing I am using the latest version of EF and I am also using Unity as my IOC. PROBLEM The service layer of my application accesses the DataContext in the Data layer via an Interface. public class TestService : ITestService { private readonly IDataContext _context; public TestService

Entity Framework skipping Identity column Concurrency Check

不想你离开。 提交于 2019-12-12 02:51:51
问题 I am working with Entity Framework 5 code-first and I have a situation where I have an entity which has an Identity column that is not part of the primary key. When I add a new record and invoke SaveChanges on the context, I get a ConcurrencyException . If I change the primary key on the entity map to SCHED_ID or remove SCHED_ID from the entity map altogether, SaveChanges completes without issue. I suspect that since SCHED_ID is defined as an int, it defaults to a value of zero and Entity

How to get ID of Entity When Using Generic Repository Pattern c#

时间秒杀一切 提交于 2019-12-12 02:46:58
问题 Trying to figure out how to get the Id of the recently added entity when using Generic Repository pattern. An example would be nice. here's the Repository, public class Repository<T> : IRepository<T> where T : class { protected DbContext DbContext { get; set; } protected DbSet<T> DbSet { get; set; } public Repository(DbContext dbContext) { if (dbContext == null) throw new ArgumentNullException("dbContext"); DbContext = dbContext; DbSet = DbContext.Set<T>(); } public virtual void Add(T entity)

EF5 Fluent API byte array to long

ε祈祈猫儿з 提交于 2019-12-12 02:12:06
问题 Using EF5 Fluent API does anyone know if it's possible to have a binary column in the database but a long in the C#? When we put a long in the entity we always end up with EF errors at runtime (unable to perform the mapping). If we put a byte[] then everything works (binary in db usually means byte[] type in .NET code). We can't change database column type so it's not a solution. Here is what we end up doing : from l in LeadDataRepository.GetAll() select new { // we need an anonymous type

How to tell EntityFramework 5.0 that there's a one-to-one association between two entities?

让人想犯罪 __ 提交于 2019-12-12 01:56:52
问题 I could go into the EDMX in design view and update the cardinality (1- , 0- , etc.) of associations, but I want to know if it is alright to do that in this scenario. I have these two tables, let's say: User ----- Id UserProfile ------------- Id UserId Stuff A single user may have just one profile. Therefore, I have set a UNIQUE constraint no the UserId column in the UserProfile table. Also, UserProfile.Id is defined as a foreign key that references User.Id . However, in the Entity Framework

How to relate two unrelated foreign keys back to the same entity

断了今生、忘了曾经 提交于 2019-12-12 01:37:36
问题 Using EF code first, I created compound primary key on Packages and Services consisting of Id and Member_Id . Then I made foreign keys from both of those tables into Promises . As you can see it didn't relate the two foreign keys back to the same Member thus allowing the package member to be different than the service member. This is not what I intended. I intend to have Promises just have a single Member_Id column and reuse it in both foreign keys. In problem terms, I intend for promises to