小编Doa*_*ong的帖子

如何在Entity Framework 5中获取已修改对象的列表

我是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)

c# winforms entity-framework-5

22
推荐指数
1
解决办法
2万
查看次数

Convert.ToBase64String/Convert.FromBase64String和Encoding.UTF8.GetBytes/Encoding.UTF8.GetString之间的区别

我目前正在学习.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)

c# cryptography

13
推荐指数
1
解决办法
1万
查看次数

Deserialize xml into super class object with C#

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)

c# xml-deserialization

7
推荐指数
1
解决办法
1173
查看次数

迭代到IEnumerable <T>和List <T>之间的性能

今天,我在迭代一系列项目时遇到了性能问题.在完成一些诊断之后,我终于找到了降低性能的原因.事实证明,迭代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)

c# ienumerable list

7
推荐指数
2
解决办法
9557
查看次数

实体框架 6 没有导航属性的一对多关系

我有 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)

问题

当我从上下文中检索时BInstanceOfClassA始终为空。

假设

B由于实体中没有引用导航属性,因此实体框架在检索时A不会延迟加载。AB

期待

因为我不需要B从访问A,因此我想摆脱 中的导航属性,但仍然保留从 中A延迟加载的能力。AB

笔记

我看到了没有导航属性的映射多对多关系的帖子,但这不适合我的情况。

无论如何,我可以在不使用显式 include 的情况A下强制延迟加载吗?也许是习惯惯例B …

c# ef-code-first entity-framework-6

5
推荐指数
1
解决办法
3369
查看次数

使div自动调整大小以适应其容器高度

我有这样的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/

html css

3
推荐指数
1
解决办法
1万
查看次数

将MVC3模型映射到MSSQL 2008 View首先使用代码,然后使用数据库

在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

3
推荐指数
1
解决办法
1504
查看次数

如何重定向已登录的用户尝试访问登录页面MVC3

我正在使用MVC3进行表单身份验证.除了一件事,一切都很好.我想在他/她再次尝试访问LogOn页面时将经过身份验证的用户重定向到另一个页面.那我该怎么做呢?

asp.net-mvc-3 form-authentication

3
推荐指数
1
解决办法
1326
查看次数

自定义TableViewCell的UIImageView出口nil

UITableViewCell在情节提要上创建了一个原型单元,然后将其链接到ImageViewCell继承自的单元UITableViewCell。我IBOutlet为原型单元上的每个控件创建了一个控件,其中包含一些UILabelUIImageView。当我尝试将数据填充到这些控件中时,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)

objective-c uitableview uiimageview ios

1
推荐指数
1
解决办法
991
查看次数

[UIView setImage:]:初始化UISearchController时将无法识别的选择器发送到实例

我正在开发具有功能的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)

ios swift uisearchcontroller

1
推荐指数
1
解决办法
571
查看次数

对象#<HTMLDivElement>没有方法'空'

我对此很困惑.我正在使用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)

jquery

0
推荐指数
1
解决办法
2463
查看次数