很多人都有很多的解脱 [英] Many to many releation

查看:67
本文介绍了很多人都有很多的解脱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个可以在asp.net MVC3网络应用程序中做的实现。



我必须与多对多关系的实体。我已经有两个类的控制器和视图,但我的问题是我无法弄清楚如何实现两个实体之间的crud关系。



我的两个课程如下:



Hey i have a implementation i can to figure out to do in asp.net MVC3 web application.

I have to Entities with a many to many relation. I have already existing controller and views for both classes, but my problems is i can''t figure out how to implement the crud relation between the two entities.

My two classes are as following:

public class Recipe
    {
        public int RecipeID { get; set; }
        [MaxLength(255)]
        public string Title { get; set; }
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }
        [DataType(DataType.MultilineText)]
        public string Story { get; set; }
        public string ImageUrl { get; set; }
        public virtual ICollection<RecipeIngredient> Ingredients { get; set; }
    }







public class Ingredient
    {
        public int IngredientID { get; set; }
        public string Name { get; set; }
        public virtual IngredientCategory Category { get; set; }
    }





这些论文是由持有一些额外信息的实体组成的:



Theses are joinet by an entity holding some extra information like this:

¨
public class RecipeIngredient
    {
        public int RecipeIngredientID { get; set; }
        public int IngredientID { get; set; }
        public int RecipeID { get; set; }
        public string Amount { get; set; }
        public string Measurement { get; set; }
        public virtual Recipe Recipe { get; set; }
        public virtual Ingredient Ingredient { get; set; }
    }





太好了。然后我将其添加到配方编辑视图中。





Soo far so good. Then i have added this to the recipe edit view.

Add ingredients: 
        <input id="txtAmount" type="text" />
        <select id="Select1">
            <option>DL</option>

        </select>
<input type="text" name="completeMe" id="completeMe" />
        <input type="submit" value="Search" />
        </p>
<script type="text/javascript">

$(function() {

$("#completeMe").autocomplete({
    autoFocus: true,
    source: '/Recipe/AutoCompleteIngredients',
    minLength: 1,
    select: function(event, ui) {
    }
});
});

</script>





我希望能够添加通过在输入字段中搜索成分和键入数量和测量值来确定成分。使用jquery自动完成功能进行搜索工作正常,但我无法理解我如何从jquery自动完成中获取所选成分并创建RecipeIngredient。



我知道另一个解决方案是复选框方法,但这不是我想要的。我似乎无法找到任何这方面的例子,甚至不知道我是做正确的方法还是其他方式会更好。



非常感谢任何帮助。

/ Anders



I want to be able to add ingredients by searching for ingredient and typing amount and measurement in the input fields. Searching works fine with jquery autocomplete, but i can''t wrap my head around how i takes the selected ingredient from the jquery autocomplete and creates an RecipeIngredient.

I know a other solution is the checkbox approach, but this is not what i want. I can''t seem to find any examples on this, and don''t even know if i''m doing the right approach or a entire other way would be better.

Any help is greatly appreciated.
/Anders

推荐答案

function (){


#completeMe ).autocomplete({
autoFocus: true
source:' / Recipe / AutoCompleteIngredients'
minLength: 1
select: function (event,ui){
}
});
});

< / script >
("#completeMe").autocomplete({ autoFocus: true, source: '/Recipe/AutoCompleteIngredients', minLength: 1, select: function(event, ui) { } }); }); </script>





我希望能够添加通过在输入字段中搜索成分和键入数量和测量值来确定成分。使用jquery自动完成功能进行搜索工作正常,但我无法理解我如何从jquery自动完成中获取所选成分并创建RecipeIngredient。



我知道另一个解决方案是复选框方法,但这不是我想要的。我似乎无法找到任何这方面的例子,甚至不知道我是做正确的方法还是其他方式会更好。



非常感谢任何帮助。

/ Anders



I want to be able to add ingredients by searching for ingredient and typing amount and measurement in the input fields. Searching works fine with jquery autocomplete, but i can''t wrap my head around how i takes the selected ingredient from the jquery autocomplete and creates an RecipeIngredient.

I know a other solution is the checkbox approach, but this is not what i want. I can''t seem to find any examples on this, and don''t even know if i''m doing the right approach or a entire other way would be better.

Any help is greatly appreciated.
/Anders


在我看来,自动完成会给你一个成分的名称和ID。然后,您将输入其余信息(数量等),然后将这些值存储在数据库中(可能在调用中首先检查该成分是否已在配方中,如果是,则更新它。) />


你的连接类有两个对象的id,为什么它也包含对象的实例?这不是EF,对吧,它只是你的类'写作?
It looks to me like the autocomplete will give you the name and id of an ingredient. Then you will type in the rest of the information( quantity, etc ) and then store those values in the DB ( probably in a call that checks first if that ingredient is already in the recipe and, if so, updates it instead.

Your joining class has the ids of both objects, why does it contain instances of the objects as well ? This is not EF, right, it''s just classes you''re writing ?


这篇关于很多人都有很多的解脱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆