Questions tagged [ef4-code-only]

86 questions
3
votes
1 answer

EF4 CTP5 self-referencing hierarchical entity mapping

Okay, this should be really easy, but I've been tearing my hair out. Here's my POCO (which has to do with machine parts, so a part can be contained within a parent part): public class Part { public int ID { get; set; } public string Name {…
Hobbes
  • 31
  • 3
3
votes
2 answers

Fluent mapping verification for Entity Framework 4

Note: This is a follow-up question for this previous question of mine. Inspired by this blog post, I'm trying to construct a fluent way to test my EF4 Code-Only mappings. However, I'm stuck almost instantly... To be able to implement this, I also…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
2
votes
1 answer

Anonymous type with Linq to Entity(EF 4.1)?

Suppose I want to fetch data into an anonymous object (i.e. fetch data from two or more tables and store it in a variable) at some part of my application development with a Linq to Entity query. Later I need a Razor View to access this…
2
votes
1 answer

Intercepting and logging changes with EF 4.2 code first

I spent some time reading a few posts and articles about audit tracking but still can't figure this out. What I need is a pretty basic audit system that will give me results such as: Customer "John Doe" was deleted by "User" Customer "Jane Doe" was…
2
votes
3 answers

Lazy Loading not working

I'm having trouble using EF Code first 4.1 and am probably not understanding something. My understanding is that by marking relationships (whether collections or single objects) as virtual, they will be lazy loaded on demand, so I could do something…
Clyde
  • 8,017
  • 11
  • 56
  • 87
2
votes
2 answers

How to reuse part of Linq to Entity Select expression in EF4.1 code only scenario

Here is very simplified version of code that i have: class PrintJob : IEntity { public string UserName { get; set; } public string Departmen { get; set; } public int PagesPrinted { get; set; } } class PrintJobReportItem { public int…
2
votes
0 answers

WCF Data Services and Entity Framework 4.1 Complex Types

I'm using WCF Dataservice to get my entities from DbContext. My Entities have a complex type which contains some metadata (DateTime and Guid properties). Here is my code: var uri = new Uri(webServiceUrl); service = new…
2
votes
1 answer

code first CTP5 error message

I get the following error message with a new project I have set using code first CTP5. Can't find anything on the web about it. Has anyone encountered this error message? The context cannot be used while the model is being created. This occurs the…
user482833
  • 111
  • 2
  • 8
2
votes
3 answers

Retrieving an Entity Object by name - LINQ to Entities, EF 4.0

I have a number of entity objects that are structurally the same but the naming convention is different e.g Products1, Products2, Products3 (this is part of the legacy db schema and I can't do much about this). These classes are of different types…
strenium50
  • 21
  • 1
2
votes
1 answer

MVC and EF4 CTP model-binding and saving hierarchical model

Am having trouble finding a clear answer to my situation when searching Stack Overflow and Google, hopefully someone can point me in the right direction. My Situation I want to be able to use a single edit form (in a single View) to update a…
Brendan
  • 1,033
  • 10
  • 12
2
votes
1 answer

how do I write this SQL in LINQ Entity Framework 4

select C.CenterID from dbo.Center C inner join (select PersonID, max(EffectiveDate) as EffectiveDate from Center where EffectiveDate <= getdate() group by PersonID) as C2 on C.PersonID= C2.PersonID and…
2
votes
1 answer

entity framework when many to many is holding data

I'm using Entity Framework CTP5. I have a schema like this: A group contains many textdescriptions. A textdescriptions has many texts. A Language has many texts. So there are 4 tables. Groups one-to-many DEscriptions many-to-many Texts many-to-one…
Syska
  • 1,150
  • 7
  • 26
2
votes
1 answer

ef4 map model defined function to property

I've seen model defined functions used in in-code queries (queries written by the developer using Linq etc) and I'm wondering if there's any way to map a model-defined function to an entity property so that EF4 will automatically query the database…
hackerhasid
  • 11,699
  • 10
  • 42
  • 60
2
votes
1 answer

EF4 TPT with abstract classes - defining relationships

I've been going around in circles with this and don't seem to be able to google the right answers - even after hours spent on this, so you're my last resort! Setup In my web app I would like to enable users to use different authentication mechanisms…
Dav
  • 1,102
  • 3
  • 10
  • 22
2
votes
4 answers

how do i create a composite key that comprises a foreign key with code first?

I am using EF4 code first and want to generate a composite key which is made of a class property and foreign key. I have two classes: Order and Company. The Order class holds a reference but this will not necessarily be unique between companies. So…