DataSource Controls :: Entity Framework Deleting Many To Many Relationship?

Jul 9, 2010

I have 3 tables User, role and UserInRole THe entity frame work made entities for User and Role and I have successfully made a join with the user and role entities using user.add(role); but I can't seem to get it to remove the link (I want to retain the user and role just remove their association).

using (ProviderEntities context = new ProviderEntities())
User u = context.User
.Where(n => n.ApplicationName == application)
.Where(n => n.Username == username).First();
Roles r = context.Roles
.Where(n => n.ApplicationName == application)
.Where(n => n.RoleName == roleName)

The oposite worked when I did r.User.Add(u); but it wont let me now remove it after it been created. Driving me mad as I can't see where I have gone wrong.

View 1 Replies

Similar Messages:

Entity Framework - One To One Relationship - Save Record?

Mar 16, 2010

I have a one-to-one relationship on two tables with are represented by 2 classes in my EDM. I am trying to save a new record and am confused how to save to the second entity. I have tried the following.

Dim myObject as new MyObject
myObject.prop1 = 5
myObject.prop2 = "Test"
myObject.myOtherObject.prop1 = 3
myObject.myOtherObject.prop2 = "Hello"

But I get an error when I hit myObject.myOtherObject.prop1 = 3 because myOtherObject hasn't been initialized. How do I initialize an child object under myObject?

View 1 Replies

Entity Framework CTP5 - Code First - Many To Many Relationship With Cascade Delete

Jan 4, 2011

I have two entities (Customer and CustomerRole) and would like to declare many-to-many relationship between them. I can do using the following code:

.HasMany(cr => cr.Customers)
.WithMany(c => c.CustomerRoles)
.Map(m => m.ToTable("Customer_CustomerRole_Mapping"));

But it creates the relationship (and the third mapping table) with cascade delete switched off by default. How can I tell EF to create the relationship with cascade delete switched on when using many-to-many?

View 1 Replies

Visually Set Controls Datasource From Entity Framework?

Feb 27, 2011

I set up Entity Framework for my Table and Stored Procedure to return data. Created a Domain Class as well.

In Domain Class, I am returning Objects as collection.

On .Aspnet page when I drop a Control(Combo,Dropdown) I can set up the source for the controls visually if the source is table.

However, In domain class I have stored precedure object that return collection of data And I cant not set up visually from Designer, I am only available to write code behind. is it possibble that i can set up from desingner.

View 6 Replies

DataSource Controls :: WEB Services And Entity Framework?

Jan 19, 2010

CAN we use Entity framework in web services.I the following error while the code connects to the database using entity framework

View 3 Replies

DataSource Controls :: Uniqueidentifiers And Entity Framework?

Feb 16, 2010

I have a sql server database that includes the field ArticleID of type uniqueidentifier that is a primary key and is set to be auto-generated by the database when a new article is added.If i generate my entity model and do the following code:


Then a new article is saved to the database but the entity framework must be generating a new blank Guid and saving that to the database rather than allowing it to be auto generated as the articleid that shows up saved is all 0.How can i get the Entity Framework to let the Database generate the ArticleId?

View 3 Replies

DataSource Controls :: How To Use A Stored Procedure In Entity FrameWork

Mar 22, 2010

i joined together more than one entity: Customer, Personel etc. i used inner join structures. if i look adonet entity framework ,5 entities are generated. i need to run this SP in C# side:


LOOK BELOW PİC : you can understand it :

MY C# codes: [Code]....

How can i get all joined data from sql with using randevu.GetRandevular(customerID

View 1 Replies

DataSource Controls :: Use Database Instead Of MDF File With Entity Framework?

Jan 11, 2010

I transfered my data from MDF files to MS SQL Database, but I can't get it working with entity framework.

My Old connection string is:

metadata=res://*/Models.EntityModel.csdl|res://*/Models.EntityModel.ssdl|res://*/Models.EntityModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|TripsDB.mdf;Integrated Security=True;User

I put all data from TripsDB.mdf to Trips table in local MS SQL 2008 Enterprise database. Also changed connection string to:

Server=WIESIEK;Database=Trips;Trusted_Connection=True;providerName=System.Data.SqlClient;User ID=Jan J. Roman

But my application throws System.ArgumentExceptio with message: The 'server' keyword is not supported.

on line:

private TripsDBEntities2 _entity = new TripsDBEntities2();where TripsDBEntities2 is Entity Framework instance.

View 2 Replies

DataSource Controls :: Stored Procedure In Entity Framework?

Jul 7, 2010

I have a stored procedure that generates a float value. I've added the stored procedure to my edmx file and created a function import, but the function isn't showing up in the object browser or via intellisense.

I'm using Visual Studio 2010 and I've verified that the stored procedure works in SSMS. Here is the current stored proc I'm using:


View 1 Replies

DataSource Controls :: Entity Framework EntityKey (Defaults To 0?)

Feb 6, 2010

Id - PK
Id - PK
TypeId - FK to CarType

I have this simple example here and I want to insert a new CarDetail into the database but for some reason I cannot get the EntityKey to work in EF4 and Framework4 beta 2.

If i declare the following

car_detail.CarTypeReference.EntityKey = new System.Data.EntityKey("MyDB.CarType", "Id", 1)

Each time i try to call SaveChanges, it throws a INSERT constraint error saying that there is a conflict between CarType and CarDetail with the FK. It just seems like the hard coded 1 for CarType is NOT being passed through but instead the default value of 0. What is going on?

If i call car_detail.TypeId = 1 then it works fine with the INSERT.

Why doesn't the EntityKey method work?

View 1 Replies

DataSource Controls :: Left Join With Entity Framework?

May 17, 2010

how to do this query in EF1:


View 3 Replies

DataSource Controls :: Viewing Fields From Two Tables Using Entity Framework

Mar 17, 2010

I have created a .edmx for the northwind database. When I run the following statement, the correct number of detail records are retrieved and I can access the detail fields, but how do I access the order header record to view OrderDate, ShipAddress, etc...?


View 1 Replies

DataSource Controls :: How To Save Multiple Rows Using ADO.NET Entity Framework

Mar 23, 2010

public void saveOptionalCourses( ArrayList coursesAdded, int studentID)
StudentOptionalCoursesXRef XRefObject = new StudentOptionalCoursesXRef();
using (var EntityObject = new SchoolProjectEntities2())
foreach ( string list in coursesAdded)
XRefObject.StudentDetails = EntityObject.StudentDetails.Where(c => c.StudentID == studentID).First();
XRefObject.OptionalCourses = EntityObject.OptionalCourses.Where(c => c.OptionalCourseName == list).FirstOrDefault();

with this above method and could save only last row that am returning remaining rows are iterated but are not saving on to database

View 2 Replies

DataSource Controls :: How To Insert A Null Into A Record Entity Framework

Feb 24, 2010

I'm using the linq to entity command to perform a record update. I want to set one of the fields back to NULL but I'm not sure how do it. I have a query such as

Dim record = From r in db.LISTS where r.ID = refID Select r
record.Title = txtTitle.text
if txtDetail.text = "" then
record.Detail =
end if

View 3 Replies

DataSource Controls :: Entity Framework - Parent And Child Relationships?

Feb 4, 2010

I am just getting started with entity framework with 3.5 using VS 2008

There are two tables, Categories & Subcategories:

Category table: CID, CategoryName Sub Category table: SID, CID, SubCategoryName I would like to get SID, CID, CategoryName, SubCategoryName in the gridview. Just as we write a select statement i.eSelect a.sid, b.cid, b.categoryname, b.subcategoryname from subcategories a inner join categories b on a.cid=b.cid & put the same in a gridview.

I was trying for the whole day & couldnt get atleast one url that would teach how to do it.

View 3 Replies

DataSource Controls :: Entity Framework And Architecture Of Model - Create Application Using EF

Feb 10, 2010

I can't to understand clearly how to create strong and quickly application using EF. For example, I have class ForumPost (table ForumPost) for select one of record I write method like:

public ForumPost ForumPost(int ForumPostID)
(from i in _dataContext.ForumPostSet
where i.ForumPostID == ForumPostID select i).First();

all works. But on page (I use ASP.NET MVC) I should display info from another linked tables, ForumName (each post have ForumID) etc. So, I modify this method to:

public ForumPost ForumPost(int ForumPostID)
(from i in _dataContext.ForumPostSet
where i.ForumPostID == ForumPostID select i).First();

ok, all works. Then I want to make some actions in model with ForumPost, i.e.

public void RootPost(int PostID, ref Models.ForumPost Root)
ForumPost post = ForumPost(PostID);
if (post.RootPost != null)
Root = ForumPost(post.RootPost.ForumPostID);
Root = post;

it works too. But problem is in speed. I not need in RootPost all those includes. So, I should to create one more method like:

private ForumPost ForumPostIncludes1(int ForumPostID)
(from i in _dataContext.ForumPostSet
where i.ForumPostID == ForumPostID
select i).First();

then ForumPostIncludes2, ForumPostIncludes3 etc... second way - redesign RootPost with LINQ expr, not with call another method. But in this way difficulties to change DB. third way? How to do it correctly?

View 1 Replies

DataSource Controls :: Best Way To Handle Inserts For Entities When Using FormViews And Entity Framework 4?

Mar 3, 2010

I am trying to get some guidance with this issue:

I have a Customer object that has two address ID fields (one for HomeAddress and one for WorkAddress)

I am loading the Address Objects by using Include="HomeAddress, WorkAddress" and then binding to the properties using the Navigation Property on the Customer Entity

Can I use just one FormView for doing the Insert/Updates and binding it to an EntityDataSource or would I have to do all the Inserting/Updating manually?

View 1 Replies

DataSource Controls :: Entity Framework - Send The Values To Be Inserted As Strings To The DAL?

Feb 5, 2010

I've sucefully created a method to insert values through EF, but i've a question (maybe, a newbie question).

Should i send the values to be inserted as strings to the DAL, and then i create the object there or should i create the object in View Layer and then send him to DAL?

Example 1 (DAL):


Example 1 (View Layer, on a click button for example):


Or should i receive the strings in DAL like this: public bool NoticiasInsert(string tituloPT, string tituloEN, string descricaoPT, string descricaoEN)

Then i create the object cdcModel.noticias and set the fields there with the strings values.

What do you advice me to do? I know that both ways works, but i'm trying to develope with better patterns (i don't know if this is the exacly word, sorry my bad english)

cdcModel.noticias campos = new cdcModel.noticias();
campos.tituloPT = "a";
campos.tituloEN = "b";
campos.descricaoPT = "a";
campos.descricaoEN = "a";
if (DAL.NoticiasInsert(campos)

View 1 Replies

DataSource Controls :: Unable To Select And Insert Data In Mapping Table Using Entity Framework

Jan 18, 2010

I have three table like above, table C is mapping table which has foreign key of Table A and B.How can i select and insert data in Table C using Entity Frame Work?

View 2 Replies

DataSource Controls :: Foreign Key Reference Not Updating With ADO.NET Entity Framework Silverlight/Data Service

Apr 8, 2010

I'm trying to insert a new EF object containing a reference to a related table via foreign key, and cannot get the reference stored in the new object. I have two tables in a SQL Server 2008 Database:

Component Templates

with a Foreign Key linking them thus: ComponentTemplates:ID [0..1<->*] PartGroups:ComponentTemplateID

I have imported these tables into a .NET web application project .edmx file (using a new ADO.NET Entity Data Model), and then created a Data Service which I then reference in a Silverlight 3.0 project. The objects are available as expected in the data context called by my Silverlight app and load correctly. Now, when I try to save a reference of ComponentTemplate into a newly created PartGroup, the PartGroup object is created in the database, but the value of ComponentTemplateID in the newly created table record is NULL.


(Note that _ctCtrl.ComponentTemplate is a confirmed non-NULL object reference to the parent object on which PartGroup is a child)

View 2 Replies

DataSource Controls :: How To Create A Self Association Relation For An Organization Chart Data Tree In Entity Framework

Mar 6, 2010

I,am trying to create a self association relation for an organization chart data tree in Entity Framework,after trying different ways for prevention of exceptions like 3007 and etc. I found that when I put my foreign key in my POCO near Parent and Items navigation properties its work.but I think this is not correct that we have both ParentID scalar property and Parent navigation property. review this and tell me is it correct or not.I'm using VS 2010 RC and ofcource .net framework 4.0 RC


View 2 Replies

C# - Deleting Selected Relations In Many-to-many Relationship In EF?

Mar 13, 2011

In SQL, I have:[Bands] 1 ---- * [BandsGenres] * ---- 1 [Genres]In my EF layer, it translates to:[Bands] * ---- * [Genres](BandsGenres is BandId and GenreId)My problem is, I can't seem to figure out how to delete just the selected relationships I need. Basically, I'm trying to update a list of type Genre for a band. A list of Guids is passed in and I'm able to get those using joins. However, the .Remove() method isn't removing the old genres and adding the new ones. I tried using .Attach(g) and .DeleteObject(g) but that removed the actual Genre (from Genres) instead of just the relationship.


How can I delete/add or update my list of genre relationships for a band, given a list of genre IDs?

View 1 Replies

Exporting Entity Framework 4 Data Model To Entity Framework 3.5?

Oct 25, 2010

Is there a way to export a EF 4.0 Data Model to EF 3.5?

I looked around and found that we are not able to access EF 4.0 from a ASP.Net 3.5 project here: [URL]

Our project is the 1st to go to .Net 4.0 using Entity Framework and we (the team) were wondering if there was a way for the other projects that "might" need to access our data that are still using the .Net 3.5 framework.

View 1 Replies

ADO.NET :: Entity Framework With Stored Procedure Versus Entity Framework Without Stored Procedures

Nov 2, 2010

I am new to entity framework , it is really very good , but I want to know what is the difference between using entity framework with stored procedure or without stored procedure , which one the faster and what is the benefits for using stored procedures with entity framework.

View 1 Replies

Entity Framework -Update Entity When Another Entity Is Updated

Jun 30, 2010

I have an EDM, it includes the entities extension and history. My goal is to use history to keep track of all the changes made to extension entity. For example, if extension with ID 223 has its property 'Name_Display' changed - I want the history entity to record this.

I'm using ASP.NET with VB.NET. Where in my code do I put the hook to say, "update the history entity" and what should that hook look like?

View 1 Replies

Copyrights 2005-15, All rights reserved