entity-framework

Get TraceString for your business objects in the Entity Framework

☆樱花仙子☆ 提交于 2020-01-07 04:44:28
问题 How do I get the trace string for a query like this: var product = _context.Products.Where( p => p.Category == "Windows" ) .SingleOrDefault(); // I can't do this since product is not an ObjectQuery instance // product.ToTraceString(); 回答1: Different answer for different problem. You can't call ToTraceString() on this: var product = _context.Products.Where( p => p.Category == "Windows" ) .SingleOrDefault(); You can do this: var q = _context.Products.Where( p => p.Category == "Windows" ) var ts

Generating Entity Framework based on Views: Nullable types

半腔热情 提交于 2020-01-07 04:30:27
问题 Some of the properties in a class generated by EF are nullable, and some arent. My first instinct was that this should be driven by Nullable property returned by sp_help MyView. But that doesn't seem to be the case. Some of my types that are returned as Nullable by sp_help get generated as Nullable , while others, get generated as just bool instead of Nullable*bool* what is it driven by, and is there any way to control it by the view? as a test i created ViewA and than ViewB which selected

Automapper projection and union

陌路散爱 提交于 2020-01-07 03:08:17
问题 I have a problem with union and automapper projections. I have two entities: public class Entity { public DateTime ActionDate { get; set; } public int SomeProp { get; set; } } public class ExtendedEntity { public DateTime ActionDate { get; set; } public int SomeProp { get; set; } public int SomeOtherProp { get; set; } } and projection: public class EntityProjection { public DateTime ActionDate { get; set; } public int SomeProp { get; set; } public int SomeOtherProp { get; set; } public string

Unable to save because of 'another entity of the same type already has the same primary key value'

隐身守侯 提交于 2020-01-07 03:05:45
问题 I have this Controller action: [HttpGet] [Route("api/person/test/{id}")] public IHttpActionResult Test(Guid id) { var person = this.PersonManager.Get(id); person.Lastname = "Jameson"; this.PersonManager.Save(person); return Ok(true); } Deep underneath this save method is called: protected void Add<T>(T source, MyEntities context, bool isNew) where T : class { if (isNew) { context.Set<T>().Add(source); } else { var entry = context.Entry(source); if (entry.State == EntityState.Detached) {

ModelConfiguration does not exist in the namespace 'System.Data.Entity'

别来无恙 提交于 2020-01-07 03:03:48
问题 I'm trying to get a template working that will correctly rename my navigation properties in the entity framework. Here are first five lines of the template: <#@ template language="C#" debug="true" hostSpecific="true" #> <#@ include file="EF.Utility.CS.ttinclude"#> <#@ assembly name="System.Text.RegularExpressions"#> <#@ import namespace="System.Text.RegularExpressions" #> <#@ import namespace="System.Data.Entity.ModelConfiguration.Mappers" #> However when I try to "Run the Custom Tool" I get

Using a DLL which in turn uses Entity Framework

我怕爱的太早我们不能终老 提交于 2020-01-07 02:53:11
问题 We are using Entity Framework in a service library for my application but don't want to have a dependency on EF in any application which makes reference to this DLL. The problem we have is the main application has two problems: It doesn't have the references to EntityFramework.dll (I think this is an MSBuild issue?) I'm required to put the connection string in the main applications App.Config file Are there any solutions for this or do we have to just accept any application using this DLL

Using a DLL which in turn uses Entity Framework

不打扰是莪最后的温柔 提交于 2020-01-07 02:53:04
问题 We are using Entity Framework in a service library for my application but don't want to have a dependency on EF in any application which makes reference to this DLL. The problem we have is the main application has two problems: It doesn't have the references to EntityFramework.dll (I think this is an MSBuild issue?) I'm required to put the connection string in the main applications App.Config file Are there any solutions for this or do we have to just accept any application using this DLL

How to stop the EDMX generator from changing columns names

橙三吉。 提交于 2020-01-07 02:31:35
问题 If a table has column names that are the same as the table name the EDMX Generator suffixes the column name with a "1". Ex: Changing Test to Test1 in the sample below. SQL Server Table definition: CREATE TABLE [dbo].[Test]( [Test] nchar NOT NULL, [ColumnsTwo] nchar NULL, EF Model created: <EntitySetMapping Name="Test"> <EntityTypeMapping TypeName="AdventureWorksModel.Test"> <MappingFragment StoreEntitySet="Test"> <ScalarProperty Name="ColumnsTwo" ColumnName="ColumnsTwo" /> <ScalarProperty

How to stop the EDMX generator from changing columns names

£可爱£侵袭症+ 提交于 2020-01-07 02:31:06
问题 If a table has column names that are the same as the table name the EDMX Generator suffixes the column name with a "1". Ex: Changing Test to Test1 in the sample below. SQL Server Table definition: CREATE TABLE [dbo].[Test]( [Test] nchar NOT NULL, [ColumnsTwo] nchar NULL, EF Model created: <EntitySetMapping Name="Test"> <EntityTypeMapping TypeName="AdventureWorksModel.Test"> <MappingFragment StoreEntitySet="Test"> <ScalarProperty Name="ColumnsTwo" ColumnName="ColumnsTwo" /> <ScalarProperty

Update model (edmx) with system tables (SYS.xxx) - Sybase

送分小仙女□ 提交于 2020-01-07 02:23:30
问题 When selecting 'update model from database' none of the system tables (SYS. schema) is available from the list of tables. How may I add a system table to my EF model. Sybase (ASA12) is the database platform which I am using. 回答1: As a workaround I created a view on the system table. It is then available and may be updated automated by the edmx generator 回答2: I created a script that recreates all the catalog views, i.e. sys.*, as views in a user schema: Note: This is T-SQL, and SQL Server