Questions tagged [ef4-code-only]
86 questions
51
votes
5 answers
How not persist property EF4 code first?
How do I make non persisted properties using codefirst EF4?
MS says there is a StoreIgnore Attribute, but I cannot find it.
http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx
Is there…

Adam Gordon Bell
- 3,083
- 2
- 26
- 53
48
votes
5 answers
How do I map a char property using the Entity Framework 4.1 "code only" fluent API?
I have an object that has a char property:
public class Product
{
public char Code
{
get;
set;
}
}
Entity Framework doesn't seem to be able to map chars (this field is missing from the database when I create the database…

dommer
- 19,610
- 14
- 75
- 137
39
votes
2 answers
using Guid as PK with EF4 Code First
I have this class and table:
public class Foo
{
public Guid Id {get;set;}
public string Name {get;set;}
}
create table Foo
(
id uniqueidentifier primary KEY DEFAULT (newsequentialid()),
name nvarchar(255)
)
the problem is that when i try to…

Omu
- 69,856
- 92
- 277
- 407
19
votes
1 answer
How map objects to a view with EF 4 code first?
How can you map an entity to a database view with EF 4 code first?
Is there a way to do this by deriving from the EntityConfiguration classes?

Adam Gordon Bell
- 3,083
- 2
- 26
- 53
18
votes
3 answers
Entity Framework 4: Code First - Creating db in another schema? MapSingleType?
I have a database and I am using two different schemas. Schemas are like namespaces (correct me if I am wrong). This way I have one database and currently two schemas, so the tables in one schema can be named the same as the tables in the other…

Martin
- 23,844
- 55
- 201
- 327
16
votes
5 answers
How do I get the raw SQL underlying a LINQ query when using Entity Framework CTP 5 "code only"?
I've using Entity Framework CTP5 in "code only" mode. I'm running a LINQ query on a object that was return from the database, as the query is running really slowly. Is there any way in which I can get the SQL statement that is being generated from…

dommer
- 19,610
- 14
- 75
- 137
14
votes
5 answers
How does EF 4 code first handle schema changes in a production environment?
Traditionally I have always written my sql scripts by hand so they are nice and clean (I'm not a fan of the generated ones) and release to release, I provide a fresh install script and a migration script from the previous version that creates new…

Joshua Hayes
- 1,938
- 2
- 21
- 39
12
votes
1 answer
DbContext SaveChanges Order of Statement Execution
I have a table that has a unique index on a table with an Ordinal column. So for example the table will have the following columns:
TableId, ID1, ID2, Ordinal
The unique index is across the columns ID1, ID2, Ordinal.
The problem I have is that when…

didiHamman
- 798
- 1
- 9
- 19
12
votes
3 answers
XML data type in EF 4.1 Code First
I would like to use SQL Server xml type as a column type for an entity class.
According to this thread it's possible to map such a column to string type:
public class XmlEntity
{
public int Id { get; set; }
[Column(TypeName="xml")]
public…

alexey
- 8,360
- 14
- 70
- 102
8
votes
2 answers
Use a struct in place of a primitive for a EF4 property type
I've got an EF4 entity (code-first) that includes an int bitmask. I've created a Bitmask struct to make working with bitmasks easier (provides bool properties to access the bits). The bitmask struct includes overloaded implicit operators for…

Brian
- 37,399
- 24
- 94
- 109
7
votes
1 answer
Access DbContext from IQueryable
I am trying to implement a caching pattern which may need to utilise Redis. The problem with this pattern is that I need to disable Configuration.ProxyCreationEnabled and then re-enable it afterwards to avoid any issues across a web farm.
What I…

didiHamman
- 798
- 1
- 9
- 19
7
votes
3 answers
How Refactor Code/DB schema with EF 4 code first - Data Migration
What are the best practices for database refactoring with codefirst EF4?
I am interested to hear how people change the classes and the database when the RecreateDatabaseIfModelChanges option is not feasible. Migration of data will need to…

Adam Gordon Bell
- 3,083
- 2
- 26
- 53
7
votes
2 answers
Inherit a common base class in EF code first
I'm converting my EF POCO project to Code first. I had changed the T4 template, so that all my entities use a base class, EntityBase, that provides them with some common functionality that is not persistence related.
If I use [NotMapped] attribute…

Alireza
- 5,421
- 5
- 34
- 67
6
votes
0 answers
EF4 Selftracking Entity
I'm wokring on building dataAcess layer for my application I'm using EF4 Self tracking entities I build entities quit well now I have to seprate self entities to their files so I can use for N tiers.
So far I did follow this…

aajay
- 61
- 2
6
votes
2 answers
How can I add an Image type to an EF4 Code First Entity?
How can I add an Image type to an EF4 Code First Entity? I need to add a column for thumbnail images.
public Image Thumbnail { get; set; }
Thanks!

Jamey McElveen
- 18,135
- 25
- 89
- 129