entity-framework-6

Do I have to reference the Entity Framework 6 dll in all Projects? (not only my DAL)

北战南征 提交于 2019-12-05 23:37:11
Question - Do applications really have to install EF6 to consume another class library that used EF6 as it's underlying data retrieval mechanism (or am I mistaken)? - How can I work around this and still use EF? Scenario We are rewriting an old DAL with a new version that uses EF6 to get it's data. Consumer apps don't call on the EF context. They instead call intermediate functions (in a Business Logic folder in the DAL project), that in turn calls on EF. When I have a consuming app reference my new DAL (connection string and provider references added to it's .config), the compiler complains

EF Database first how to update model for database changes?

这一生的挚爱 提交于 2019-12-05 23:07:25
In a class library Ado.net Entity Data Model is has generated POCO classes. These were generated fine for the first time. But database changes are not being reflected. In edmx diagram right clicking and choosing Update Model from Database show newly created table but it do not add table even after selecting it to add. I tried running .tt (by right click and Run custom tool) but even it did not regenerated the Poco classes as per latest DB changes. Help please Not a fix but a workaround: Is it not an option to simply remove and regenerate the EDMX and the generated classes? That's what I do, it

Hooking IDbInterceptor to EntityFramework DbContext only once

这一生的挚爱 提交于 2019-12-05 22:06:13
问题 The IDbCommandInterceptor interface is not very well documented. And I've only found a few scarce tutorials on it: http://www.entityframeworktutorial.net/entityframework6/database-command-interception.aspx https://msdn.microsoft.com/en-us/data/jj556606%28v=vs.113%29.aspx https://entityframework.codeplex.com/wikipage?title=Interception https://www.tutorialspoint.com/entity_framework/entity_framework_command_interception.htm https://msdn.microsoft.com/en-us/data/dn469464%28v=vs.113%29.aspx And

How do I map a column to uppercase in .NET 4.5 C# Entity Framework 6 using both Oracle and SQL Server?

时光毁灭记忆、已成空白 提交于 2019-12-05 20:08:58
I'm using C#, .NET 4.5 and Entity Framework 6 in my project. It uses both Oracle and SQL Server, depending on the installation at the client. The approach is database-first, as this database existed already by the time we decided to change the ORM from NHibernate to Entity Framework 6. The mapping looks like this: ToTable(schema + ".Motorista"); Property(x => x.Criacao).HasColumnName("criacao").IsOptional(); The table and column names are all in PascalCase in the mapping, which works fine with SQL Server but, in Oracle, all the names are UpperCase which causes an error: ORA-00942: table or

Get ignored properties in Entity Framework

三世轮回 提交于 2019-12-05 19:48:56
I work on a framework with EF. I want to get all ignored properties of an entity to build some special queries. How can I do it? public class Customer { public int Id { get; set; } public DateTime BirthDate { get; set; } public int Age { get; set; } } public class CustomerContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Customer>().Ignore(customer => customer.Age); base.OnModelCreating(modelBuilder); } public DbSet<Customer> Customers { get; set; } } public static class DbContextExtensions { public static List<string>

How to specify the shape of results with WebApi2, OData with $expand

[亡魂溺海] 提交于 2019-12-05 19:05:45
I have a problem executing my AutoMapper mappings when using OData with specific $select or $expand values. Using the WebApi Action: public IQueryable<BookInRequestDto> Get(ODataQueryOptions<BookInRequest> query) { var results = query.ApplyTo(_context.BookInRequests) as IQueryable<BookInRequest>; var mappedResults = Mapper.Map<IQueryable<BookInRequest>, IQueryable<BookInRequestDto>>(results); return mappedResults; } When I query: api/Get , I get an appropriate response, but a Document's Properties is set to null response containing documents properties set to null. When I query: api/Get?

Generic Merge of DbContext: how to check if entity is all ready attached?

回眸只為那壹抹淺笑 提交于 2019-12-05 18:52:20
问题 Given the following code: void MergeDbContext(DbContext aSourceDbContext, DbContext aDestinationDbContext) { var sourceEntities = aSourceDbContext.ChangeTracker.Entries().ToList(); foreach (DbEntityEntry entry in sourceEntities) { object entity = entry.Entity; entry.State = EntityState.Detached; // check if entity is all ready in aDestinationDbContext if not attach bool isAttached = false;// TODO I don't know how to check if it is all ready attched. if (!isAttached) { aDestinationDbContext

Issues Generating .edmx EF6 in Visual Studio 2013

♀尐吖头ヾ 提交于 2019-12-05 18:21:08
I am trying to generate my edmx file for my database in Visual Studio 2013 against either a mssql 2012 or 2008 database server and table set. The edmx file generates with out issue, and everything looks fine until i try to compile the project. Every single object representing a database table errors out with the following messages. A using namespace directive can only be applied to namespaces; 'System' is a type not a namespace The type name 'Collections' does not exist in the type 'Model.blah.System' The type name 'DateTime' does not exist in the type 'Model.blah.System' The using statements

How to define a one to one self reference using Entity Framework Code First

时光总嘲笑我的痴心妄想 提交于 2019-12-05 18:06:18
I want to implement versioning on my entity Stuff . Each entity has an optional reference to the next version (the latest version will be null) and an optional reference to the previous version (the first version will be null). I am using entity framework 6, code first. I tried with the following model and modelbuilder statement (and many variations). public class Stuff { public int StuffId { get; set; } [ForeignKey("NextVersion")] public int? NextVersionId { get; set; } [InverseProperty("PreviousVersion")] public virtual Stuff NextVersion { get; set; } public virtual Stuff PreviousVersion {

NullReferenceException in EF 5-6.1.1 with two navigation properties to the same type

房东的猫 提交于 2019-12-05 17:50:48
I'd like to start with that I have a workaround for this issue - but I spent a few hours today figuring out the cause of the exception, so I'd thought I'd share Given two entities in the domain: public class User { public int Id { get; set; } public string Name { get; set; } } public class Ticket { public int Id { get; set; } public string Name { get; set; } public virtual User Owner { get; set; } public int? LockedByUserId { get; set; } public virtual User LockedByUser { get; set; } [Timestamp] public byte[] ETag { get; set; } } The following configuration: public class TicketConfiguration :