如何将对象序列化为查询字符串格式?我似乎无法在谷歌上找到答案.谢谢.
这是我将序列化的对象作为示例.
public class EditListItemActionModel
{
public int? Id { get; set; }
public int State { get; set; }
public string Prefix { get; set; }
public string Index { get; set; }
public int? ParentID { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 命令: add-migration blahblah -verbose
错误:序列不包含任何元素
在收到此错误之前我做了一些事情.我对代码优先模型进行了更改,但尚未运行add-migration.然后我添加了一个EDMX模型来直观地展示一个想法.我意识到EDMX模型弄乱了我的代码所以我删除了它.我试图运行add-migration并得到"序列不包含任何元素".我升级到EF 5并卸载旧的Migrations包,但我的配置除外.然后我add-migration再次尝试,我仍然得到"序列不包含任何元素".以下是错误的其余部分.
System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.GetQualifiedTableName(XDocument model, String entitySetName)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<FindRenamedIndependentAssociationColumns>b__ba(<>f__AnonymousType16`2 <>h__TransparentIdentifieraa)
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Linq.Enumerable.<DistinctIterator>d__81`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, String connectionString)
at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges)
at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Sequence contains no elements
Run Code Online (Sandbox Code Playgroud) .net entity-framework ado.net-entity-data-model edmx ef-code-first
这是一个我正在研究的非常简单的条形图,
<div id="container">
<div style="display:inline-block;">
</div>
<div style="display:inline-block;">
</div>
<div style="display:inline-block;">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果我将容器设置为relative而内部div设置为absolute和bottom:0,那么它们都会重叠.它们在没有绝对定位的情况下很好地流动,但条形图是颠倒的.
注意:我的意图是保留条形的内联流,而不必明确指定水平位置.
这是问题的一个更好的例子.
http://jsfiddle.net/benstenson/NvvV6/1/

1) correct orientation but vertical alignment is top
<div id="no-content" class="container">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
</div>
2) wrong orientation, vertical alignment top
<div id="has-content" class="container">
<div class="a">a</div>
<div class="b">b</div>
<div class="c">c</div>
</div>
3) mixed orientation, alignment is crazy
<div id="mixed" class="container">
<div class="a">a</div>
<div class="b">b</div>
<div class="c"></div>
</div>
4) correct orientation and correct alignment but<br/>
flow has been lost and …Run Code Online (Sandbox Code Playgroud) 如何获取List所包含类型派生的所有DbSet IncomingServiceOrderBase?
我可以使用反射来获取所有DbSet,但是如何将其过滤到包含派生类型的那些?
上下文
public class MyContext : DbContext
{
public DbSet<BuildingOrder> BuildingOrders { get; set; }
public DbSet<DeliveryOrder> DeliveryOrders { get; set; }
public DbSet<RetailAssemblyOrder> RetailAssemblyOrders { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
模型
public class BuildingOrder : IncomingManufacturedProductOrderBase { }
public class DeliveryOrder : IncomingServiceOrderBase { }
public class RetailAssemblyOrder : IncomingServiceOrderBase { }
Run Code Online (Sandbox Code Playgroud) c# generics reflection entity-framework entity-framework-4.1
如何选择第一个"最浅"的输入?
我当前的选择将是标记为"已选择"的div.
我不知道会有多少级别.
<div class="selected"> <!-- already have this -->
<div class="unknown-number-of-wrapper-panels">
...
<div class="collection">
<div class="child">
<input type="text" value="2" /> <!-- don't want this -->
</div>
</div>
<input type="text" value="2" /> <!-- need this -->
<input type="text" value="2" />
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
它似乎find().first()给了我最深刻的一个.
编辑清晰.我需要根据它较浅而不是基于其他独特属性的事实来找到它.
这可能就像是反过来的closest()?
我想制作一个这样的方法,
public dynamic Traverse(dynamic entity, conditions, method)
{
foreach (var propInfo in GetTraversableProperties(entity))
{
if (condition) method(propInfo.GetValue(etc));
Traverse(propInfo, condition, method);
}
return entity;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?将条件和方法作为参数传递的语法是什么?另外,使条件成为方法并检查它的返回值更有意义吗?
我试图这样做,但它说我不能使用FirstOrDefault,
public static int GetId(this Context db, Type type, string name)
{
return db.Set(type).FirstOrDefault(x => x.Name == name).Id;
}
Run Code Online (Sandbox Code Playgroud)
错误是' System.Data.Entity.DbSet'不包含'FirstOrDefault'的定义,并且没有可以找到接受类型'System.Data.Entity.DbSet'的第一个参数的扩展方法'FirstOrDefault'(你是否遗漏了) using指令或程序集引用?)
我然后尝试了这个Cast方法,但是给出了一个错误无法从非泛型DbSet为'WindowStyle'类型的对象创建一个DbSet(顺便说一下,WindowStyle从DomainEntity下面继承),
var set = db.Set(type).Cast<DomainEntity>();
return set.FirstOrDefault(x => x.Name == name).Id;
Run Code Online (Sandbox Code Playgroud)
这是班级,
public class DomainEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud) string thing = "etc";
thing = thing.GetName();
//now thing == "thing"
Run Code Online (Sandbox Code Playgroud)
这甚至可能吗?
public static string GetName(this object obj)
{
return ... POOF! //should == "thing"
}
Run Code Online (Sandbox Code Playgroud) 我安装了打印机并在Intranet服务器上工作,我想以编程方式将"hello world"发送到该默认打印机.这似乎是最简单的事情,但我一直在谷歌搜索几个小时没有成功.(注意:我正在运行Windows 7的部署机器上开发asp.net mvc)
我试图从VB翻译的例子在这里为C#,但它说:"没有安装打印机".
public void TestPrint()
{
var x = new PrintDocument();
x.PrintPage += new PrintPageEventHandler(PrintPage);
x.Print();
}
private void PrintPage(Object sender, PrintPageEventArgs e)
{
var textToPrint = "Hello world";
var printFont = new Font("Courier New", 12);
var leftMargin = e.MarginBounds.Left;
var topMargin = e.MarginBounds.Top;
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, leftMargin, topMargin);
}
Run Code Online (Sandbox Code Playgroud)
我还曾试图片段从MSDN 这里,但它说,它不承认打印机名称.
public void TestPrint(string msg)
{
var server = new LocalPrintServer();
var queue = LocalPrintServer.GetDefaultPrintQueue();
// Call AddJob
var job = queue.AddJob();
// …Run Code Online (Sandbox Code Playgroud) 该参数string[] orderTypeNames将为null.
mvc行动
public PartialViewResult EditMultipleOrderStates(
string[] orderTypeNames,
int[] orderIds)
Run Code Online (Sandbox Code Playgroud)
JavaScript的
$('#edit-mulitple-order-states-button').click(function () {
ids = [];
types = [];
$checked = $('.order-queue-order input:checked');
$orders = $checked.closest('.order-queue-order');
$orders.each(function (index, elem) {
$order = $(elem);
ids.push($order.attr("orderId"));
types.push($order.attr("orderType"));
});
data = {
orderIds: ids,
orderTypeNames: types
};
$.post('EditMultipleOrderStates', data, function (response) {
//...
});
});
Run Code Online (Sandbox Code Playgroud)
小提琴手

orderIds%5B%5D=97&orderIds%5B%5D=98&orderIds%5B%5D=93&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder
Run Code Online (Sandbox Code Playgroud)
是方括号导致问题吗?我怎样才能绑定到这些数组?
编辑:我在同一时间手动构建查询字符串.
query = "";
for each...
query += "orderIds=" + $order.attr("orderId") + "&";
query += "orderTypeNames=" + $order.attr("orderType") + "&";
Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×3
asp.net-mvc ×2
html ×2
javascript ×2
jquery ×2
reflection ×2
action ×1
asp.net ×1
c#-4.0 ×1
css ×1
css-position ×1
dbcontext ×1
edmx ×1
generics ×1
methods ×1
object ×1
position ×1
predicate ×1
printing ×1
query-string ×1
stack-frame ×1