Supose I have 2 tables
usersTable
userid guid not null
username nvarchar
...more fields
ArticleTable
Articleid int not null
Article ntext
userid guid not null
username nvarchar not null
...more fields
To add an article, a user has be loged in. So I do this to get their userId and username
' get the user currently logged in
...
I am having problems trying to map an existing legacy database.
In this example a Country has many Cities.
The problem is the foreign key on the City table is not the primary key of the Country table
Table Definitions
CREATE TABLE [dbo].[CD_Country](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Code] [char](2) NOT NULL,
[Name] [nvarchar](50...
Hi,
I want to create a entity model from the existing database but all the table names contain "_"/underscore in the database so while creating poco classes i want remove underscore from name of the entities/poco classes. Is there a way to change the naming convention while the entities are created in the entity framework during the cre...
I am experiencing an issue with EF4 and Proxy Pocos.
I have 2 classes with the same name in the same assembly but different namespaces:
QuoteModels.CashPayment
OrderModels.CashPayment
This compiles fine but at runtime EF throws the following exception:
Schema specified is not valid. Errors:
\r\nThe mapping of CLR type to EDM
...
Hi All
I've been reading Scott Gu's post on code first design with ASP.Net MVC 2.0 and EF4 here:
http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
In the post he uses the SQL CE4 database for development and 'seeds' test data.
My question is related to testing. It is widely regar...
Hi,
I'm trying to generate my database tables from my Entity Framework model, but I'm getting this error when I execute the generation query:
Database 'Database' does not exist. Make sure that the name is entered correctly.
I'm able to connect to the local server just fine.
My connection string, which was generated by VS when I sele...
Hi,
I have 2 tables: Bikes and Wheels. Bike has 2 FKs to Wheels: Bike.FrontWheelID and Bike.BackWheelID.
EF maps these onto Bike.Wheel and Bike.Wheel1, just using their type for name, which I would prefer to avoid.
Is there a way to change this that would survive further regenerations of model from db schema? (some setting perhaps?)
T...
Hi,
Is it possible to read CSV file using Entiry Framework 4 such that it should give me an entity that I can use it normally within my application?
Thanks
...
Sorry this is quite a vague question. Been trying to find information on using a View with Entity Framework 4. Want to use it as a read only view, no interested in inserting/updating/deleting... Would just like to use a POCO with a view...
[Update]
Thanks to the responders. Zeeshan, actually reading your book currently.
I can add a vi...
Hi,
I have an existing database containing an article and a blog table. These have common columns such as title, author repeated in the two tables. I want to utilise entity framework to create a Content entity that pulls in the common properties so i can inherit the Content entity in the Article and Blog entity.
The idea being that I ...
Because as I make small changes it regenerates the the entire DB and therefore removes the data..
I suppose I could manually maintain a script that I run that inserts the test data after I regenerate the schema.
Or is there a better way to go about doing this?
...
Hi
I am reading the Entity Framework 4.0 recipe. In chapter 2, it has a bunch of recipes for modeling our entities relationship ( Table per Type, one to many, ...) basing on the relationship table.
My question is that EF will automatically create models to match our database tables relationship already. So why do we need to remodel our ...
We have a situation with a fairly complex entity/table hierarchy modelled with EF4. Often we like most of the associations to load (whether lazy or not) and are happy with that.
Sometimes we want just the top of the hierarchy and maybe one or two of the related detail tables to be attached. For example when returning a set from a WCF ...
Considering this class
public class XQueries
{
public IQueryable Query1()
{
using (XEntities context = new XEntities())
{
return something;
}
}
public IQueryable Query2()
{
using (XEntities context = new XEntities())
{
return somethingElse;
}
...
I'm getting
System.NotSupportedException: All
objects in the EntitySet
'Entities.Message' must have unique
primary keys. However, an instance of
type 'Model.Message' and an instance
of type 'Model.Comment' both have the
same primary key value
but I have no idea what this means.
Using EF4, I have a bunch of entities of ...
I have the following table structure that Entity Framework is correctly returning as a one-to-many:
Patient
{
PatientId PK
}
Death
{
DeathId PK
PatientId FK
}
Unfortunately this DB design is wrong as you can only have one Death per Patient. The design should of been like this instead:
Death
{
PatientId PK
}
However, th...
This is a method for add/update an entity using Self Tracking Entities, what is the equivalent using POCO?
public Hero SaveHero(Hero hero)
{
using (WarEntities model = new WarEntities())
{
if (hero.ChangeTracker.State == ObjectState.Added)
{
mode...
I used to use NHibernate with repository interfaces.
What is the proper way to use this pattern with EF?
How can I implement this repository interface, for a RepositoryBase<T>?
public interface IRepository<T>
{
T GetById(object id);
void Save(T entity);
T[] GetAll();
void Delete(T entity);
}
...
Given the following query:
var query = from item in context.Users // Users if of type TblUser
select new User() // User is the domain class model
{
ID = item.Username,
Username = item.Username
};
How can I re-use the select part of the statement in other quer...
The site I am working on has the concept of a User and a Site. A User can join the global site and create mini sites within (www.globalsite.com/minisite). The Users can also Follow other mini sites created by other users. Think about it like if Twitter allowed you to join with one set of credentials and create different accounts, one for...