English 中文(简体)
准则与实体更新
原标题:LINQ to Entities Update Query

我试图做一个简单的更新,但我能为我的生活做些什么是错的。

我有以下的法典目前尚未奏效,我根本不希望所有法典道路都恢复价值。

public List<tblWeight> UpdateFeedback(string memberid, string locationid, int prikey, string feedback)
{

        MyEntities updatefeedback = new MyEntities();

        tblWeight newfeedback = (from q in updatefeedback.tblWeights
                                 where q.MemberId == memberid &&
                                       q.LocationId == locationid &&
                                       q.PriKey == prikey
                                 select q).SingleOrDefault();

        updatefeedback.tblWeights.AddObject(newfeedback);
        updatefeedback.SaveChanges();

}

基本上,我正试图根据条款的哪些内容,在拖拉机内更新反馈栏。

任何人都能够指出,我会错过哪儿......dr!

  • Sorry - the previous try/catch was legacy.
最佳回答

首先(原因与你的问题不同),排除了障碍:

       catch (Exception)
        {
            return null;
        }

第二,你说,你回到了<代码>List<tblWala>,但你在职能的任何地点都没有这样做。 你们要么需要最终在试场内返回挪威民族解放军,要么最好是在有人适当居住的<代码>List<tblWala>架构内返回。

你们说的客人要么返回,要么改变返回“避免”的职能,要么放弃。

就例外情况而言,请看一下处理例外情况的最佳做法。 我在担任这一职务时重申了这一点,因为此前曾多次说过。 我向各位保证,如果你的话,你会更快地书写代码,减少编码,并撰写更好的编码。

问题回答

您的<代码>UpdateFeedback方法被定义为返回List<tblWala>,但在一切顺利运行(即没有出现例外)的情况下,没有返还,这是C#的汇编错误。

我建议,你完全摆脱审判/渔获区,因为追捕而不是重温例外的做法非常恶劣。 如果说有些错误的话,你就应该有一个例外,告诉你为什么。

那么,你要么需要退还一些具有意义的物品(例如,return Updatefeedback.tblWalas),要么需要改变拥有的保值(即不退还任何款项)。

审判团内部没有返回,或者不是你要求什么?

错误指出,并非所有法典都具有价值,这是真实的。

You only return a value (null) if you catch (and swallow) an exception. The normal (hopefully) path does not return anything.

你们要么在“拯救”之后回来,要么把回报价值变为无效。





相关问题
LINQ Training: Native SQL Queries to LINQ

Can anyone point out some good LINQ training resources. Mostly interested in getting some developers that are very skilled with SQL up to speed using Lambda and LINQ queries. They are struggling with ...

How can i write Linq2Entities Query with inner joins

How can I get data from these related entities. I want to get these columns only: Term.Name , related Concept_Term.Weight, related Concept.Id I wrote the SQL but I don t want to use select t....

Linq to enties, insert foreign keys

I am using the ADO entity framework for the first time and am not sure of the best way of inserting db recored that contain foreign keys. this is the code that i am using, I would appreciate any ...

Linq to entity timing problem

I created a data model that has some views from my database as entities,when I create a linq statment that has part of this view s entities ,the time processor take to execute the linq statment is ...