entity-framework-6

How to find a date with a list of specified date ranges in Entity Framework?

寵の児 提交于 2019-12-12 07:24:55
问题 I have an IEnumerable of a class that I created to contain date ranges. That class looks like this: public class Range<T> where T: struct { public T Start { get; set; } public T End { get; set; } } I want to find all the records in my set where a date column falls within ANY of the specified date ranges. This was my attempt: deals = deals.Where( deal => criteria.DateRanges.Any( dt => deal.CloseDate >= dt.Start && deal.CloseDate < dt.End.Value.AddDays(1))); This throws an error I assume

EntityFramework.SqlServer.dll not is getting added to the published folder only when I publish in RELEASE mode

为君一笑 提交于 2019-12-12 07:14:40
问题 I know there is a problem with EF6 EntityFramework.SqlServer and included var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices); in context constructor. It works fine when i do publish in DEBUG mode. Getting the below error only when I publish in RELEASE mode. The reason is EntityFramework.SqlServer.dll missing in the published folder. But, bin folder has EntityFramework.SqlServer.dll for both debug and release mode. Error: The Entity Framework provider type 'System.Data.Entity

How would I pass a constructor parameter at runtime to my dbContext and also register them with Unity as such

两盒软妹~` 提交于 2019-12-12 05:44:33
问题 I am trying to implement all sorts of good stuff like UnitOfWork, Repository, DI. I am using Unity for DI. Here is my dilemma. I have a few (currently 3) databases with identical schema but obviously with different data for business reasons (I will call them GroupDB1, GroupDB2 and GroupDB3). I also have a Master Database (DifferentDB) that has a different schema. My dbcontext need to use different databases for different scenarios at runtime. I have no clue how to put them all to work

Entity object cannot be referenced by multiple instances of IEntityChangeTracker in a generic repository

陌路散爱 提交于 2019-12-12 05:39:26
问题 i have used a generic interface and repository in this tugberkugurlu, which is... public interface IGenericRepository<T> where T : class { IQueryable<T> GetAll(); IQueryable<T> FindBy(Expression<Func<T, bool>> predicate); void Add(T entity); void Delete(T entity); void Edit(T entity); void Save(); } and this generic repository public abstract class GenericRepository<C, T> : IGenericRepository<T> where T : class where C : DbContext, new() { private C _entities = new C(); public C Context { get

Entity Framework Code First unique index foreign key throws DbUpdate Exception

时光怂恿深爱的人放手 提交于 2019-12-12 05:29:38
问题 Here's the entites and context code: public class Family { public int FamilyID { get; set; } public String address { get; set; } public virtual ICollection<Member> FamilyMembers { get; set; } } public class Member { [Index("MemberUniqueID", IsUnique = true)] public int MemberID { get; set; } [StringLength(50)] [Index("MemberUniqueIndex", 1, IsUnique = true)] public String name { get; set; } [StringLength(50)] [Index("MemberUniqueIndex", 2, IsUnique = true)] public String surname { get; set; }

Entity Framework Mapping Issue

好久不见. 提交于 2019-12-12 05:27:56
问题 In my EF code, I am using classes based on the EntityTypeConfiguration<T> class to perform configuration. In these classes, I have helper methods to aid in the configuration. For example, I have the following code: protected void MapGuidColumn(Expression<Func<T, Guid>> selector, string columnName, bool isRequired, bool isIdentity) { PrimitivePropertyConfiguration configuration = null; configuration = this.Property(selector); configuration.HasColumnName(columnName); if (isRequired == true) {

Why can't EF handle two properties with same foreign key, but separate references/instances?

感情迁移 提交于 2019-12-12 05:17:46
问题 Apparently, EF6 doesn't like objects that have multiple foreign key properties that use the same key value, but do not share the same reference. For example: var user1 = new AppUser { Id = 1 }; var user2 = new AppUser { Id = 1 }; var address = new Address { CreatedBy = user1, //different reference ModifiedBy = user2 //different reference }; When I attempt to insert this record, EF throws this exception: Saving or accepting changes failed because more than one entity of type 'AppUser' have the

How to map two One or Zero to One relationships

我是研究僧i 提交于 2019-12-12 05:06:02
问题 I have three entities with the name of SellinRequest, MortgageAndRent and Album. Each of SellinRequest and MortgageAndRent may have an Album. public class SellingRequest { public int Id { get; set; } public Album Album { get; set; } } public class MortgageAndRent { public int Id { get; set; } public Album Album { get; set; } } public class Album { public int Id { get; set; } public SellingRequest SellingRequest { get; set; } public int SellingRequestId { get; set; } public MortgageAndRent

Schema specified is not valid. Errors: The relationship 'Product_CreatedByUser' was not loaded because the type 'User' is not available

大憨熊 提交于 2019-12-12 04:57:29
问题 I have following code first models and I try to initialized database it giving me error mention below. One user can have multiple products so there is one to many relationship between user and product. Schema specified is not valid. Errors: The relationship 'Models.Product_CreatedByUser' was not loaded because the type 'User' is not available. I am using code first approach, can any one help me with this. User: public class User { public long UserId { get; set; } public string FirstName { get

Entity Framework 6 - Dependency Injection with Unity - Repository pattern - Add or Update exception for many to many relationship

回眸只為那壹抹淺笑 提交于 2019-12-12 04:55:23
问题 I have a problem when adding new values with a many to many mapping in Entity Framework. I know about the unit of work pattern but in our solution we would like to keep a simple repository pattern and not a unit of work class that contains everything. Is this possible or should I just implement Unit of Work right away? If I don't use iSupplierRepository below a supplier will be added, but it will always add a new one even though there already exists one with that name. Error: The relationship