entity-framework-4

Entity Framework 4 many to many doesn't delete the actual entity

I have an EF4 model over a SQL Server 2008 db. In my model I have a many to many relationship: Articles * - * Comments and Projects * - * Comments In my Model, I simply created an association and set it up to many to many. In my db, I then get two additional tables ArticleComments and ProjectComments, which only hold the primarykeys...

Entity Framework 4.0 and Stored Procedures

Are there any examples/articles on how to use the Entity Framework 4.0 Code First model (no edmx or xml configuration anywhere!!!) that interacts with stored procedures? Another aspect to my requirements is I am using a Repository pattern that uses an IRepository interface to abstract the actual data store (memory, database, xml, etc). ...

Is Entity Framework ObjectContext correct implementation of Unit Of Work Pattern?

Entity Framework 4 - STE - simple DB with single table Blogs having BlogID PK column... var samplesDbEntities = new SamplesDBEntities(); var blogId = Guid.NewGuid(); samplesDbEntities.Blogs.AddObject(new Blog() { BlogID = blogId }); var objectSetResult = samplesDbEntities.Blogs .Where(p => p.BlogID...

Is it possible to load an Excel file to memory?

I have a website where businesses can load items for sale. Then end users can search for that item, and find all the stores that carry it. Most stores sell more than 100 things, and while I do have a form for inserting a single item, it's tremendously stupid to have only this for businesses to offer things. My idea is to have an option...

Insert New Data using Linq -- WCF Data Services (formerly ADO.NET Data Services)

I am really struggling to insert some data into 2 database tables. I am using Linq over WCF Data Services using Entity Framework 4. The 2 tables look like this: CREATE TABLE [dbo].[Accounts] ( [Id] int IDENTITY(1,1) NOT NULL, [Email] nvarchar(max) NOT NULL, [Password] nvarchar(max) NOT NULL ); CREATE TABLE [dbo].[Employ...

EF4 code only approach for many-to-many relationships

I have the following: Product POCO ProductConfiguration class for EF code only (CTP3) Product table in database ProductCrossSell table in database My Product and ProductConfiguration class looks like: public class Product { public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual IColl...

Struggling With Entity Framework 4

Hi guys, Please I need help on how to handle CRUD in ef4 way. I started a project on asp.net mvc1 and ef v1 .net 3.5 sp1, but along the line after the release of vs 2010 I converted the application to asp.net mvc2 and ef4 .net4 after some reading on the new features both technologies offers. Right now am kinda stock as things don't app...

Repository in T4 template

I am writing a T4 template for repositories. Say we have Customers/Orders/Products tables. We then have CustomerRepo, OrdersRepo, and ProductsRepo. Is it a good practice to have a generic repo for all of them? public partial class Repository { private IContext context; public Repository() { _Product = new ProductRepo(); _Cu...

Combing tables with one-to-many relationships into a single entities in ADO.NET Entity Framework 4.0

Hi, I'm aware you can map multiple storage tables to a single entity if they have a one-to-one relationship in EF 4.0. Example: (storage) (1)Table: People Columns: Name, Age (2)Table: Customers Columns: Registered -- Relationship: People <1-1> Customers (concept) Entity: Customers Columns: Name, Age, Registered I'm wo...

entity framework 4, code-only, relationships

Hi, I can't figure out how to solve the following problem. What i need it a relationship from one base class to another, so that every derived class has a relationship with the same table, called 'Item' in my example. Since this is just an example it doesn't reflect my program. In the real program the relationship with class Item is in...

c# Linq query question with EF4 table per type Inheritance

I have been searching for way to perform a linq query to get an object graph based on a specific child inheritance type. I may have prased this a little wrong, but I will try to explain. Lets say I have a EF4 model that has a City entity, a subdivision entity, a house entity and a feature entity. The city has a one to many relationshi...

EF4 "Code Only" - How to set default value for POCO's

In Entity Framework 4, Code Only (CTP3), how do you set a default value for a property in the POCO's EntityConfiguration class? public class Person { public int Id { get; set; } public string Name { get; set; } public DateTime CreatedOn { get; set; } } public class PersonConfiguration : EntityConfiguration<Person> { public PersonCo...

Adding new Scalar types to EF 4

Entity framework maps DB types to .NET types, for instance SQL Server's BigInt is mapped to .NET's long. Is it possible to create a new type and have a store type (such as BigInt or VarChar) mapped to it? If so, how? FYI, my goal is to change the way the .NET scalar writes its value to the query, and specifically the way its default v...

how do we alias a sql server instance name

I have two development teams, that come from different groups. Group A develops against a local default instance of Sql Server 2008 R2; Group B develops against a local named instance of Sql Server 2008 R2. Is there a way to setup an alias such that both groups are coding against the same name. As it stands right now we have a war o...

What class should have ability to set a password (Repository, User, etc)?

I'm using Entity Framework 4. I'm not really sure where the responsibility of setting a user's password should be. I thought about on the Repository like SetPassword(User user, string password). But it doesn't seem right. The main problem is that it can't just be a simple property setter since I also return the salt that's generated. ...

Always exclude property from Entity Framework 4 Query

I have a user entity with the following properties that map to a field in the database: Id int Username varchar(25) Password binary(64) Salt binary(64) Name varchar(50) Locked bit What I don't want to do is always return the Password and Salt for every query. But for certain queries, I do want...

Entity Framework 4 -- possible to call a SSDL function from within another SSDL function's commandtext?

Is it possible to call a SSDL function from within another SSDL function's CommandText? For example, let's say I have the following SSDL function defined in my edmx file: <Function Name="blah" IsComposable="false"> <CommandText> ...blah related stuff... </CommandText> <Parameter Name="blah_param" Type="int" /> </Function> C...

How to specify name for entity configuration

Hi, I'm using code-first in entity-framework 4, Entity Framework Feature CTP 3 Is it possible to specify an entity configuration's name? In effect changing the table name from 'xxxSet' to a name of my choice? ...

Looking for a complete example of Entity Framework 4 Code First

Hi, I've found various snippets on the web of how to use Code First in EF4 (from the futures CTP). But I have yet to find a complete example of an object context, the context builder and a more advanced EntityConfiguration. For example, in my entity configuration, how do I map a property on my domain object to a column with a differen...

Many-To-Many Relationship in Code-First EF4

How do you represent a many-to-many relationship in the EF4 Code-First CTP3? For example if I have the following classes: class User { public int Id { get; set; } public string Name { get; set; } public ICollection<Profile> Profiles { get; set; } } class Profile { public int Id { get; set; } public string Name { ge...