以下是我的模型:
public class TMUrl
{
//many other properties
//only property with type Keyword
public List<Keyword> Keywords{get;set;}
}
public class Keyword
{
//many other properties
//only property with type TMUrl
public List<TMUrl> Urls{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
很明显,两个实体都有多对多的关系.我选择了流畅的api告诉实体框架关于这种关系,即
modelBuilder.Entity<TMUrl>
.HasMany(s => s.Keywords)
.WithMany(s => s.URLs).Map(s =>
{
s.MapLeftKey("KeywordId");
s.MapRightKey("UrlId");
s.ToTable("KeywordUrlMapping");
});
Run Code Online (Sandbox Code Playgroud)
但是当我这样做的时候
url.Keywords.Add(dbKey); //where url is object of TMUrl,
//dbKey is an existing/new object of Keyword
db.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
我得到例外
An error occurred while saving entities that do not expose foreign key
properties for their relationships.... …Run Code Online (Sandbox Code Playgroud) 我想在我的MVC应用程序中加入两个实体,通过LINQ连接进行数据处理.
为此,我试图编写查询,如,
from enumeration in db.Enumerations
join cust in db.Customers on ( enumeration.Value equals cust.lkpStatus &&
enumeration.EnumerationTypeID.Contains('Cust')
Run Code Online (Sandbox Code Playgroud)
但是我对这个查询有疑问,所以请给我一些建议.
我一直在尝试使用for循环填充数组并使用这些值 document.getElementById("spin " + i).value;
将ids在我的HTML对于每个输入标签去从SPIN1到spin18.
对我做错了什么建议?或者我可以改变什么?
var nums = [];
for(var i = 1; i <= 18; i++){
var num[i] = parseInt(document.getElementById("spin" + i).value);
nums.push(num[i]);
}
alert(nums.length);
Run Code Online (Sandbox Code Playgroud) 我有CSS :hover类的问题.如何禁用:hover第二行内的第二个表类.
这是小提琴
HTML
<table border="0" width="100%" id="product-table">
<tr>
<td colspan="2">Title of the table</td>
</tr>
<tr>
<td width="20%"><b>Text text</b></td>
<td>someting about product</td>
</tr>
<tr>
<td><b>text text</b></td>
<td>
<table border="0" width="100%">
<thead>
<tr bgcolor="#ddd">
<td colspan="6"><strong>Title of inside</strong></td>
</tr>
<tr bgcolor="#efefef">
<td width="20%"><strong>No</strong></td>
<td width="20%"><strong>Date</strong></td>
<td width="20%"><strong>Define</strong></td>
</tr>
</thead>
<tbody id="hat_ekle">
<tr>
<td>123</td>
<td>2013</td>
<td>some text</td>
</tr>
<tr>
<td>234</td>
<td>2013</td>
<td>some text</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
CSS
#product-table tr:hover { background:#333; }
Run Code Online (Sandbox Code Playgroud) 我已经多次看过这个话题,但没有一个解决方案对我有帮助,我不知道为什么没有任何作用.
我有一个C#web部分,我只是想读取http post请求的数据内容.在请求中有一些xml,但是当我尝试在Web部分中读取它时,这不会显示出来.它只给我标题数据和一些服务器变量.
我正在尝试阅读的请求是通过Chrome的Simple Rest扩展提交的.当我用fiddler监视时,我可以看到请求,当我点击TextView时,我可以看到所有的XML都没有问题.那么为什么它不显示在服务器上?
我尝试使用Context.Request.SaveAs(),但似乎只给我标题数据.我也尝试循环遍历Context.Request.Params并打印每个参数,但它们都不包含xml.
最后,我尝试使用读取请求的内容
Context.Request.ContentEncoding
.GetString(Context.Request.BinaryRead(Context.Request.TotalBytes))
Run Code Online (Sandbox Code Playgroud)
并且
string strmContents = "";
using (StreamReader reader = new StreamReader(Context.Request.InputStream))
{
while (reader.Peek() >= 0)
{
strmContents += reader.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
但这两种方法都会导致空字符串.
让我感到困惑(并加剧)的是,如果我查看Context.Request.ContentLength它,它与我的XML中的字符数相同!我知道内容已经过去,但我不知道如何访问它.
我有一个非常简单的要求
public class A
{
public int Index{get;set;}
public B ConfigOne{get;set;}
public B ConfigTwo{get;set;}
public void SetConfigOne(string val1, string val2);
public void SetConfigTwo(string val1, string val2);
}
public class B
{
public string Val1{get;set;}
public string Val2{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我如何安排我的两堂课,以便我能够做到这一点:
var a = A.ConfigOne.Val1;
Run Code Online (Sandbox Code Playgroud)
但不是
A.ConfigOne.Val1 = a;
Run Code Online (Sandbox Code Playgroud)
所以基本上我想让我的间接类(B)属性只读,仍然可以在类A中设置。我想通过一个方法公开setter。我怎么做?
c# ×4
html ×2
asp.net-mvc ×1
css ×1
for-loop ×1
hover ×1
http ×1
javascript ×1
linq ×1
linq-to-sql ×1
loops ×1
many-to-many ×1
post ×1
request ×1
xml ×1