我是entities
这样的数据网格视图的绑定列表:
var orders = context.Order.ToList();
BindingList<Order> orderList = new BindingList<Order>(orders);
dataGridView1.DataSource = orderList;
Run Code Online (Sandbox Code Playgroud)
用户可以直接在datagridview上编辑或添加新内容.当用户单击Save
按钮时,为了优化性能,我想检索已更改/新的实体列表以执行插入/更新.我怎样才能做到这一点?
编辑定义向gridview添加新行:
BindinList<Order> orders = (BindingList<Order>)dataGridView1.Datasource;
order.Add(new Order());
Run Code Online (Sandbox Code Playgroud)
编辑2解决:
BindinList<Order> orders = (BindingList<Order>)dataGridView1.Datasource;
Order order = new Order();
context.Order.Add(order);
order.Add(order);
Run Code Online (Sandbox Code Playgroud) 我目前正在学习.NET中的Symmetric Cryptography.我写了一个演示如下:
private byte[] key = Encoding.ASCII.GetBytes("abcdefgh");
private byte[] IV = Encoding.ASCII.GetBytes("hgfedcba");
private byte[] encrypted;
public Form1()
{
InitializeComponent();
}
private void btnEncrypt_Click(object sender, EventArgs e)
{
this.textBox2.Text = this.Encrypt(this.textBox1.Text);
}
private void btnDecrypt_Click(object sender, EventArgs e)
{
this.textBox3.Text = this.Decrypt(this.textBox2.Text);
}
private string Encrypt(string plainText)
{
try
{
using (DESCryptoServiceProvider crypto = new DESCryptoServiceProvider())
{
crypto.Key = this.key;
crypto.IV = this.IV;
ICryptoTransform transform = crypto.CreateEncryptor(crypto.Key, crypto.IV);
using (MemoryStream stream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream(stream, …
Run Code Online (Sandbox Code Playgroud) I'm creating a program that allow user define formulas with on 4 basic operation: add, subtract, divide, multiple using XML. Let's take an example: User want to define formula like (a + b) x (c + d)
. The format of the xml as following:
EDIT I had implement this
编辑解决.非常感谢Yaniv的建议.我的解决方案如下:
<xPlugins>
<xPlugin>
<Multiple>
<Add>
<Operator>
<value>1</value>
</Operator>
<Operator>
<value>2</value>
</Operator>
</Add>
<Add>
<Operator>
<value>3</value>
</Operator>
<Operator>
<value>4</value>
</Operator>
</Add>
</Multiple>
</xPlugin>
</xPlugins>
Run Code Online (Sandbox Code Playgroud)
类
//root element
public …
Run Code Online (Sandbox Code Playgroud) 今天,我在迭代一系列项目时遇到了性能问题.在完成一些诊断之后,我终于找到了降低性能的原因.事实证明,迭代IEnumerable<T>
一次比花费更多的时间List<T>
.请帮我理解为什么IEnumerable<T>
比慢List<T>
.
UPDATE基准上下文:
我正在使用NHibernate从数据库中获取项目集合IEnumerable<T>
并对其属性值进行求和.这只是一个没有任何引用类型的简单实体:
public SimpleEntity
{
public int Id {get;set}
public string Name {get;set}
public decimal Price {get;set}
}
Public Test
{
void Main()
{
//this query get a list of about 200 items
IEnumerable<SimpleEntity> entities = from entity in Session.Query<SimpleEntity>
select entity;
decimal value = 0.0;
foreach(SimpleEntity item in entities)
{
//this for loop took 1.5 seconds
value += item.Price;
}
List<SimpleEntity> lstEntities = entities.ToList();
foreach(SimpleEntity item in …
Run Code Online (Sandbox Code Playgroud) 我有 2 个表:A 和 B 具有一对多关系,这些表在 EF 6 中实现如下:
public class A
{
[Key]
public int AID {get;set;}
public string AName {get;set;}
}
public class B
{
[Key]
public int BID {get;set;}
public string BName {get;set;}
public int AID {get;set;}
[ForeignKey("AID")]
public A InstanceOfClassA {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
问题
当我从上下文中检索时B
,InstanceOfClassA
始终为空。
假设
B
由于实体中没有引用导航属性,因此实体框架在检索时A
不会延迟加载。A
B
期待
因为我不需要B
从访问A
,因此我想摆脱 中的导航属性,但仍然保留从 中A
延迟加载的能力。A
B
笔记
我看到了没有导航属性的映射多对多关系的帖子,但这不适合我的情况。
无论如何,我可以在不使用显式 include 的情况A
下强制延迟加载吗?也许是习惯惯例B …
我有这样的HTML:
<div class="container">
<div class="banner"></div>
<div class="left"></div>
<div class="right">
<div class="content"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这些div
是根据其内容自动调整大小overflow: auto
.现在我遇到了一个问题.当div:content
溢出其母公司,div: right
以及div: container
将调整以适应div:content
高度.但div: left
身高保持不变.如何在高度变化时使div: left
高度自动调整大小以适应div: container
?
这里有一个jsfiddle:http://jsfiddle.net/trongcuong1710/cDqSj/2/
在SQL Server 2008中,我有一个这样的视图:
CREATE VIEW products AS
SELECT a.ID, a.Name, b.ID as SubID, b.Name as SubName
FROM main_product as a
INNER JOIN sub_product as b on a.ID = b.mainID
Run Code Online (Sandbox Code Playgroud)
这是我的模特:
Public class Products
{
public int ID { get; set; }
public int Name { get; set; }
public int SubID { get; set; }
public int SubName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在我如何将MVC3的视图映射到SQL Server视图?
UPDATE
我试过这个:
public class PartialContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); …
Run Code Online (Sandbox Code Playgroud) sql-server entity-framework sql-view ef-code-first ef-database-first
我正在使用MVC3进行表单身份验证.除了一件事,一切都很好.我想在他/她再次尝试访问LogOn页面时将经过身份验证的用户重定向到另一个页面.那我该怎么做呢?
我UITableViewCell
在情节提要上创建了一个原型单元,然后将其链接到ImageViewCell
继承自的单元UITableViewCell
。我IBOutlet
为原型单元上的每个控件创建了一个控件,其中包含一些UILabel
和UIImageView
。当我尝试将数据填充到这些控件中时,UILabel
效果很好,但UIImageView
始终为零,并且不会显示任何图像。码:
@interface ImageTableViewCell : UITableViewCell
@property (readonly, nonatomic, strong) Post *post;
// set value for post
- (void)setPost:(Post *)post;
@end
@implementation ImageTableViewCell
{
__weak IBOutlet UILabel *titleLabel;
__weak IBOutlet UILabel *descriptionLabel;
__weak IBOutlet UILabel *pointLabel;
__weak IBOutlet UIImageView *imageView;
}
- (void)setPost:(Post *)post
{
_post = post;
// update ui
titleLabel.text = self.post.title;
descriptionLabel.text = self.post.descriptions;
pointLabel.text = self.post.point;
[imageView setImage:[UIImage imageNamed:@"mylocalimage.png"]];
}
@end …
Run Code Online (Sandbox Code Playgroud) 我正在开发具有功能的iOS应用程序,该功能可用于UISearchController
提供国家/地区列表的搜索功能。直到最新版本,一切正常。但是现在,在向应用程序中添加了一些新功能之后,我遇到了一个奇怪的错误,该错误导致应用程序崩溃。每当我尝试打电话时UISearchController(searchResultsController:nil)
,我的应用就会因故崩溃[UIView setImage:]: unrecognized selector sent to instance
。我追溯了从先前发行版到现在的所有先前提交,但仍然没有找到罪魁祸首。我想就如何调试此问题提出建议,因为我无法调试进入UISearchController
初始化本身。
注意:我没有提供一些代码段,因为我认为这没有必要,我尝试了几种方法,包括UISearchController(searchResultsController:nil)
在其他地方调用,删除的使用UISearchController
,删除了一些可疑的扩展...以确保swift不会给我带来另一个错误崩溃报告
编辑我的应用程序的目标版本是8.0,我在XCode 7.3.1,MacOS El Capitan上使用swift 2.2
编辑2我尝试切换到,[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
但不幸的是,出于相同的原因仍然崩溃。
编辑3来自Crashlytics的崩溃日志:
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x181ec2db0 __exceptionPreprocess
1 libobjc.A.dylib 0x181527f80 objc_exception_throw
2 CoreFoundation 0x181ec9c4c __methodDescriptionForSelector
3 CoreFoundation 0x181ec6bec ___forwarding___
4 CoreFoundation 0x181dc4c5c _CF_forwarding_prep_0
5 UIKit 0x18710f9d0 -[UISearchBar(UISearchBarStatic) _updateMagnifyingGlassView]
6 UIKit 0x18710d778 -[UISearchBar(UISearchBarStatic) _setupSearchField]
7 UIKit 0x18719d2c8 -[UISearchBar searchField]
8 UIKit 0x187114684 -[UISearchBar setPlaceholder:]
9 …
Run Code Online (Sandbox Code Playgroud) 我对此很困惑.我正在使用jquery 1.9.1将div的内部html附加到另一个div.但是当尝试使用chrome开发人员工具进行调试时,它在jquery库中给了我这个错误.
我的Html:
<body>
<s:form action="/save" method="POST">
<div class="educationForm">
<div class="educations">
<label>Position</label>
<input type="text" name="educations[0].index" value="1" />
<br/>
<label>School</label>
<input type="text" name="educations[0].school" />
<br/>
<label>Degree</label>
<input type="text" name="educations[0].degree" />
<br/>
<label>GPA</label>
<input type="text" name="educations[0].scored" />
<br/>
<label>Start Date</label>
<input type="text" name="educations[0].startDate" />
<br/>
<label>End Date</label>
<input type="text" name="educations[0].endDate" />
<br/>
</div>
</div> <a href="#" id="addButton">Add new Edu</a>
<input type="submit" value="Save" />
</s:form>
<div class="template_educations" style="display:none">
<div class="educations">
<label>Position</label>
<input type="text" name="educations[_X_].index" />
<br/>
<label>School</label>
<input type="text" name="educations[_X_].school" />
<br/>
<label>Degree</label> …
Run Code Online (Sandbox Code Playgroud) c# ×5
ios ×2
cryptography ×1
css ×1
html ×1
ienumerable ×1
jquery ×1
list ×1
objective-c ×1
sql-server ×1
sql-view ×1
swift ×1
uiimageview ×1
uitableview ×1
winforms ×1