Given the following POCO classes:
public class Certification {
public int Id { get; set; }
public virtual ICollection<Employee> CertifiedEmployees { get; set; }
}
public class Employee {
public int Id { get; set; }
public virtual ICollection<Certification> Certifications { get; set; }
}
Creating the database model usi...
Using Microsoft Visual C# 2010 Express, Entity Framework Feature CTP4.
I tried EF4 with code first with something small based on Scott Gu's blog. But it seems that collections are not initialized when retrieving an entity. I get a null reference exception when adding a product to a category. In all the examples I've seen, the collection...
I am trying to figure out something with EF4 Code Only. If i use TPH and i wanted to change a saved Person to Instructor or vice versa, how would i accomplish this. My POCO classes:
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
publi...
So I have a model in my domain similar to this:
public class Product
{
public virtual Tag Methodology { get; set; }
}
Then in an webform project I update it like so:
if (!string.IsNullOrWhiteSpace(ddlMethodology.SelectedValue))
product.Methodology = TagRepo.GetTagById(int.Parse(ddlMethodology.SelectedValue));
else
product...
Is there a way in Entity Framework 4 (using CTP4 and Code First if that matters) to change the conventions used to automatically identify primary and foreign keys? I'm trying to use EF with a legacy database that uses a "pk/fk" prefix rather than an "id" suffix to mark keys. Also, it's not uncommon to have multiple foreign keys to an A...
I would like to use a lazy-loading collection on a model, but I want Add/Remove functionality to be done through separate methods. So something like this:
class Model
{
protected virtual ICollection<Something> _somethings { get; set; }
public IEnumerable<Something> Somethings
{
get { return _somethings; }
}
public vo...
I have a parent object book, and a property of that object is publisher. Everytime I ad a book, it is adding a new publisher, even if the publisher already exists. Can someone tell me how to add the book and instead of adding the publisher again, just reference an existing one? The code i am using is below... Thanks in advance!
publ...
Hi,
I want to execute stored procedure with one parameter that returns table using EF4 "Code First". I am ok with some DTO just for this purpose, it doesn't have to return entities. I have tried to:
a) create edmx file with function import and add it to my ObjectContext like this:
protected override void OnModelCreating(ModelBuilder m...
The error message :-
"The model backing the 'AddressBook' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the RecreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, a...
My entity name is "Contact" and my table name is "Contact". However, the default pluralization support is making EF4 to look for a table named "Contacts". Anybody has any idea on how to turn off the pluralization support?
This post has got some details on pluralization support. But still does not give me an answer.
I see the following...
I'm using code-first pattern for database layer.
I have two POCO classes:
public class Order
{
[Key]
public int OrderId { get; set; }
public virtual ICollection<Item> Items { get; set; }
// other fields
}
and
public class Item
{
[Key]
public int ItemId { get; set; }
public virtual ICollection<Order> Order...
If I have an entity that has an association (e.g. Book.Publisher), how do I save a new Book and associate it with an existing Publisher?
BTW I don't want to expose FK associations (i.e. PublisherId) in my model.
I had been using something like this:
var book = new Book { Title="whatever", Publisher = new Publisher { Id = 42 } };
cont...
My problem is that when I add a new entity with a required field, the entity doesn't show the validation error in the UI. I'm using using EF CTP4 Code First. My setup :
I have an entity.
public class Category
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string ImageUrl ...
I'm working on an ASP.NET MVC app, designing the domain models, using (testing) the new EF Code First feature.
I have an Activity entity that may or may not have a Deadline, what is the best way to approach it?
1 property:
public DateTime? Deadline {get; set;}
and check vs null before using
or
2 properties:
public DateTime Deadl...
I have the following Entity Framework POCO classes:
public class Customer
{
public int Id {get;set;}
public string Name {get;set;}
public virtual ICollection<Order> Orders {get;set;}
}
public class Order
{
public int Id {get;set;}
public int CustomerId {get;set;}
public int OrderTypeId {get;set;}
public v...
I've just had a massive blonde moment*, but it's highlighted an annoyance I have with Entity Framework. I have disabled lazy loading so I'm forcing myself to actually think about what data I require in order to keep the application as fast as possible.
So in order to return data within a query, I need to make use of the Include method:...
Hi,
I'm trying to map my entities using Entity Framework "code first", but I have a problem with mapping a complex type. Here my simplified exampled:
Domain object looks like:
public class Customer
{
public Address DeliveryAddress {get; set;}
}
public class Address
{
public string StreetName {get; set;}
public string Stre...
EDIT: this happen only on larger scale projects with repositories. Is there anybody using EF4 with code first approach and using repositories? please advice me
Hi. Im currently working with EF4 Code First Classes. In my test project I got two classes, Author and Book (author got books). What I'm trying to do is that I HAve a AddBook in ...
I an developing a page where users will be able to add and modify existing content, its not a wiki per sé but sort of, like SO's editing abilities.
I am working with EF4 and the new Code First approach in the latest CTP, so what would be the best class design for this?
my current guess is something like this:
public class VersionableT...
I'm hoping there will be a crazy linq answer to this, it feels like there should be
Current code:
MapHierarchy().Case<Folder>(f => new { FolderId = f.Id,
f.Name,
Type = 1 })
.Case<RootFolder>(f => new { f.RootName,
...