ADO.NET导航属性(ADO.NET Navigation Properties)
我在ADO.NET上使用导航属性和继承时遇到了一些问题。
这是我的数据模型:
首先,一些词汇:
分类=类别
Formulario = Form
Campo = Field
Imagem =图像
Paragrafo =段落
Escolha =选择
Texto =文字
Resposta =答案所以,我正在尝试在Form上创建一个自定义属性,返回它的答案数。
正常的方法(我认为)将是:
public partial class Formulario { public int Respostas { get { List<Item> itens = this.Itens.ToList(); IEnumerable<Campo> campos = from m in itens where m as Campo != null select (Campo)m; int soma = campos.Sum(m => m.Respostas.Count); return soma; } } }
但它不起作用。
itens
列表返回0个元素。 但是,当我这样做时,它返回它应该的4个项目:public partial class Formulario { public int Respostas { get { FormulariosDB db = new FormulariosDB(); List<Item> itens = db.Items.Where(m => m.Formulario.Id == this.Id).ToList(); IEnumerable<Campo> campos = from m in itens where m as Campo != null select (Campo)m; int soma = campos.Sum(m => m.Respostas.Count); return soma; } } }
它仅在我实例化整个数据模型时才有效。 有谁知道为什么?
PS:我正在使用
.toList()
方法,因此我可以使用所有Linq
查询,而不仅仅是Linq2Entities
允许我使用的I'm having a little problem using Navigation properties and inheritance on ADO.NET.
This is my Data Model:
First, some vocabulary:
Categoria = Category
Formulario = Form
Campo = Field
Imagem = Image
Paragrafo = Paragraph
Escolha = Choice
Texto = Text
Resposta = AnswerSo, I'm trying to create a custom property on a Form returning it's answers count.
The normal approach (i think) would be:
public partial class Formulario { public int Respostas { get { List<Item> itens = this.Itens.ToList(); IEnumerable<Campo> campos = from m in itens where m as Campo != null select (Campo)m; int soma = campos.Sum(m => m.Respostas.Count); return soma; } } }
But it doesn't work. The
itens
list returns 0 elements. But when I do as below, it return the 4 items it should:public partial class Formulario { public int Respostas { get { FormulariosDB db = new FormulariosDB(); List<Item> itens = db.Items.Where(m => m.Formulario.Id == this.Id).ToList(); IEnumerable<Campo> campos = from m in itens where m as Campo != null select (Campo)m; int soma = campos.Sum(m => m.Respostas.Count); return soma; } } }
It only works when I instanciate the entire data model. Does anyone knows why?
PS: I'm using the
.toList()
method so I can use allLinq
queries, not only the onesLinq2Entities
allows me to
原文:https://stackoverflow.com/questions/4215608
最满意答案
这应该让你开始。
注意:
2000
是速度 - 在2000毫秒内从这里移动到那里$(document).ready(function () { $(".img").hover( function() { $(this).animate({"right" : "640px"},2000); }, function() { $(this).animate({"right" : "0px"},2000) } ); });//END document.ready
.img-wrp { width : 400px; height : 300px; overflow : hidden; } .img { position : relative; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="img-wrp"> <img class="img" src="http://placekitten.com/1140/300" /> </div>
This should get you started.
Note:
2000
is the speed - move from here to there in 2000 milliseconds$(document).ready(function () { $(".img").hover( function() { $(this).animate({"right" : "640px"},2000); }, function() { $(this).animate({"right" : "0px"},2000) } ); });//END document.ready
.img-wrp { width : 400px; height : 300px; overflow : hidden; } .img { position : relative; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="img-wrp"> <img class="img" src="http://placekitten.com/1140/300" /> </div>
相关问答
更多-
逻辑实际上非常简单:您要做的是根据光标在文档/视口中的相对位置将图像偏离其原始位置。 我们需要在文档上的mousemove事件中执行所有这些计算。 $(document).on('mousemove', function(e) {...}); 此外,这意味着您将需要以下一些信息: 确定您希望图像从其原始位置移动的最大偏移量 视口宽度和高度 相对于视口高度的鼠标/光标位置 - 这将给出一系列[0,1] 将该范围转换为[-1,1],因为负值用于移动到顶部/左侧,而正值用于移动到底部/右侧 使用CSS3转换来移 ...
-
这是基本原则: