Click here to Skip to main content
15,887,335 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: problem with response.writefile and triggers Pin
jkirkerx31-Dec-14 9:57
professionaljkirkerx31-Dec-14 9:57 
QuestionHow must I solve this problem ? ( I don't know what it is ) Pin
Member 1134468130-Dec-14 21:45
Member 1134468130-Dec-14 21:45 
AnswerRe: How must I solve this problem ? ( I don't know what it is ) Pin
jkirkerx31-Dec-14 9:39
professionaljkirkerx31-Dec-14 9:39 
GeneralRe: How must I solve this problem ? ( I don't know what it is ) Pin
Member 113446811-Jan-15 22:25
Member 113446811-Jan-15 22:25 
Answerjquery paging&fancy box Pin
Member 1133082530-Dec-14 18:24
Member 1133082530-Dec-14 18:24 
AnswerRe: jquery paging&fancy box Pin
jkirkerx31-Dec-14 9:43
professionaljkirkerx31-Dec-14 9:43 
GeneralRe: jquery paging&fancy box Pin
Member 113308252-Jan-15 1:09
Member 113308252-Jan-15 1:09 
QuestionMVC/EF - Entity Relationship Not Being Saved Pin
Matt U.30-Dec-14 5:35
Matt U.30-Dec-14 5:35 
I'm working on a project in ASP.NET MVC, using Entity Framework 4 Code-First. The project uses the generic Repository pattern. I have an entity called "Tag", and "Tag" has a relation to entity "Right" (which is a collection). It looks like this:

C#
public class Tag
{
    public Tag()
    {
        this.Rights = new List<Right>();
    }

    public string Name { get; set; }
    public virtual ICollection<Right> Rights { get; set; }
}


In the Tag controller, there is an action method for "Edit", similar to this (modified for simplicity):

C#
public ActionResult Edit(Tag entity)
{
    var rights = _rightsRepository.Get(r => r.IsActive == true).ToList();

    entity.Rights = rights;

    Repository.Update(entity);
    UnitOfWork.Commit();
    return View("Index");
}


* "_rightsRepository" is "IRepository<right>", which, using Dependency Injection, goes to "Repository<right>" (generic Repository pattern).

There is a Mapping class set up for Tags and Rights, and the mapping is setup like this:

C#
// In the "TagMap" class
this.HasMany(t => t.Rights)
    .WithMany(r => r.Tags)
    .Map(m =>
    {
        m.ToTable("Tag_Right_Relation");
        m.MapLeftKey("RightId");
        m.MapRightKey("TagId");
    }


When debugging and setting a breakpoint in the "Edit" action method, I can step through, and the "Tag entity" has its property "entity.Rights" set accordingly, with the correct list of "Rights". However, when the actual update is called, the "Rights" collection is not persisted.

However, when using a single database Context (e.g. "MyAppContext"), it saves properly. We have a similar relation set up for the entities "User" and "Role". It maps to "User_Role_Relation". That relation uses the exact same type of method for the Tag_Right_Relation above. The Tag_Right_Relation does not work. The User_Role_Relation DOES work.

Why is it not working with objects from two different contexts for one entity type, but for another it does?


EDIT:
---------------------------

For whatever reason, it appears that the "Tag" entity is being disconnected from EF between the "Edit(int?)" action method, and the "Edit(Tag)" method. If I retrive the Tag entity from the Repository in "Edit(Tag)" and update the "Rights" collection, it works. Why is that? In other areas of the application, we don't have to do that.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.

QuestionHow to show different results based on user choices??? Pin
samflex30-Dec-14 2:50
samflex30-Dec-14 2:50 
QuestionTerelik GridView Control using Vb.Net Pin
Johndas29-Dec-14 13:48
Johndas29-Dec-14 13:48 
QuestionGridview is out of content place holder Pin
sudevsu29-Dec-14 7:07
sudevsu29-Dec-14 7:07 
AnswerRe: Gridview is out of content place holder Pin
sudevsu30-Dec-14 4:21
sudevsu30-Dec-14 4:21 
Questionbest free Treeview Pin
mrkeivan29-Dec-14 0:02
mrkeivan29-Dec-14 0:02 
QuestionPage Loader Progress Bar Pin
smit66628-Dec-14 20:44
professionalsmit66628-Dec-14 20:44 
AnswerRe: Page Loader Progress Bar Pin
Richard MacCutchan28-Dec-14 22:16
mveRichard MacCutchan28-Dec-14 22:16 
QuestionHow to pass and use web page to an external class? Pin
QuickBooksDev28-Dec-14 7:21
QuickBooksDev28-Dec-14 7:21 
AnswerRe: How to pass and use web page to an external class? Pin
syed shanu28-Dec-14 13:43
mvasyed shanu28-Dec-14 13:43 
GeneralRe: How to pass and use web page to an external class? Pin
QuickBooksDev29-Dec-14 4:10
QuickBooksDev29-Dec-14 4:10 
AnswerRe: How to pass and use web page to an external class? Pin
Dominic Burford30-Dec-14 5:44
professionalDominic Burford30-Dec-14 5:44 
GeneralRe: How to pass and use web page to an external class? Pin
QuickBooksDev31-Dec-14 0:23
QuickBooksDev31-Dec-14 0:23 
GeneralRe: How to pass and use web page to an external class? Pin
Dominic Burford31-Dec-14 0:40
professionalDominic Burford31-Dec-14 0:40 
GeneralRe: How to pass and use web page to an external class? Pin
QuickBooksDev31-Dec-14 1:36
QuickBooksDev31-Dec-14 1:36 
GeneralRe: How to pass and use web page to an external class? Pin
Dominic Burford31-Dec-14 1:56
professionalDominic Burford31-Dec-14 1:56 
GeneralRe: How to pass and use web page to an external class? Pin
QuickBooksDev4-Jan-15 5:35
QuickBooksDev4-Jan-15 5:35 
AnswerRe: How to pass and use web page to an external class? Pin
Ferd Really20-Jan-15 6:31
Ferd Really20-Jan-15 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.