http://www.cnblogs.com/lori/archive/2011/07/18/2109817.html

前提:数据底层,使用的是MVC架构,对于数据表中的状态及相关字段,采用了枚举型进行对应

 

1 序列中不包含任何元素
  解决:将Single()改为DefaultOrSingle()

2 序列包含一个以上的元素
  解决:很多情况都是原始数据的问题

3 不能在已使用的实体上添加新实体
4 Duplicate key is already ,
  3,4的解决为:用  base._db.ExecuteCommand()进行SQL语句的重写,

不要用LINQ自带的insert,就不会出现错误了

5  未将对象引用设置到对象的实例。 值不能为空。参数名: source。
   解决:  this.iProduct_ProductFilesRepository.Insert(_entity.Product_ProductFile.Cast<Entity.IDataEntity> ().ToList());,当遇到将list实体类型换为接口list规范时,应该用.Cast<接口类型>().ToList()

6 查询参数不能为“System.Object”类型。
解决:这是因为在LINQ的ExecuteCommand不理解空值,当我们传递的参数为 null 时,就会出现这个问题,解决方法是,在为实体加string.empty这个空值属性

7  Incorrect syntax near '@p0'.
解决:查看我们的SQL代码,被编译成了什么,可能是多个括号之类的。如:delete from users where (userid={0},这很明显是不对的,哈哈

8 不支持SQL的转化
   解决1,看看是否用了枚举类型,如果用了,应该先把IQueryable进行ToList,得到真正的数据后才能进行判断
   解决2,请看你的原始数据,很有可以是数据问题
   解决3,请看程序代码的关联表查询,很可能是它没有找出数据的问题

9  未将对象引用设置到对象的实例。
解决:查看数据库向数据实体赋值时,枚举类型的字段是否为null了,如果为null,就会出错

10    查询包含对不同数据上下文上所定义项的引用。
解决:查看底层工厂建立是否返回datacontext有问题,是否为空了。

11    枚举在LINQ中引发的异常:不支持SQL转换
    当枚举使用字符名称,没有数据,然它的数值存储在数据表中时,我们在返回数据时,必须在ToList()才行,否则就会出现这种问题
    例如:
     /// <summary>
     /// 以下是一个积分类型的枚举,一种类型对应数据表中同样类型的一个数值
     /// </summary>
   public enum PrestigeTypeCode
    {
           IAsk_Question,
            IAsk_Answer,
  }

  //表据表如下:
ID    描述        数值    枚举名称
1   提问           1    IAsk_Question
2   回答           1    IAsk_Answer

结论:当我们通过枚举去从数据库(SQLSERVer里)取数值时,必须要把结果集ToList()才行,如代码:
int value = new PrestigeTypesRepository().GetPrestigeTypes().ToList().Where(item => item.PrestigeTypeCode == prestigeTypeCode).Single().Amount;
如果,枚举的值,在枚举元素里读上,就不用去tolist()了

12 不能将 Null 值赋给类型为 System.Int32 (不可为 null 的值类型)的成员
解决:应该是数据的问题,Int类型的SQL表中出来了NULL值,或者是由于枚举类型转换失败的原因


 
Sunday, 24 July 2011 22:40:41 (Eastern Daylight Time, UTC-04:00)
You can also find hardly any more effective regions meant for viewing meant for adolescent, alluring, together with private men or women compared with doudounes femme , Moncler Sweater Womens ,Moncler Vest Womens , sale moncler,Moncler 2011,Moncler Mens Clothing,That i be sure my best inborn status for bliss sees a equal during the experience of someone who may be reviewing my family lake dress in my best doudounes moncler. That can put Moncler Sweater Kids all during effortless key phrases, That i appearance incredibly hot in doing my Moncler Down Coats Womens ,.
moncler jackets -usually with a pair of high heels to make you better. Besides,Tods store, the little guy is not very intimidating, depending on the percentage of his body parts in length they choose,discount doudounes femme moncler jackets,salechea, it is not strictly in accordance with the general idea,discount tods5oLldiscount todsJ'ai suivi les clubb,Tods Moncler Down Coats Mens, try not to,Moncler Jackets Womens a main,buy Moncler Vest Kids,Moncler Accessories,Moncler Handbags, do you know your Moncler Boots Womens ,Moncler Kids Clothing?

Backyard ,Moncler Down Coats Kids,Moncler Jackets Kids outfits Moncler Jackets Mens requires, to ensure simply a small section involving substantial along with brand-new technological innovation along with innovative resources are widely-used throughout modern-day outlying backyard aMoncler Sweater Mens moncler. Moncler Vest Mens,Moncler Boots Mens, involving product that is the form of manufactured fibers, normally created from polyester, nylon along with put together a number of other Moncler Womens Clothing,doudounes femme . http://www.doudounesfemmejackets.com
Wednesday, 10 August 2011 02:28:46 (Eastern Daylight Time, UTC-04:00)


Can it be Jordan Shoes truly impressive wearing Air Jordan?A man is recognized by means of his choice and preferences. Whenever you placed on Nike AJ it reveals that you are adequately considerate about your Nike Air Shoes foot wears. Carrying on these waders enhances your attitude and gives a good but stylish appear. So, don't waste more time and get one of several attractive footwear if you Air Jordan Shoes did not get it yet!

Thursday, 11 August 2011 04:21:24 (Eastern Daylight Time, UTC-04:00)
We are the top sunglasses wholesaler that provides Cheap Oakley Sunglasses that have lens featuring Oakley Hydrophobic, a permanent smudge-resistant covering that proofs water, oils and dust. Secondly, our durable lens material offers superior impact protection and filters out all rays that are harmful to your eyes. All Cheap Oakleys can provide you with excellent vision clarity. Most importantly, our Cheap Oakley sunglasses are both functional and cool. In other words, they will make other people's sight into spotlight on you. Just imagine, what a wonderful experience it will be. Come and buy Cheap Oakleys.
Friday, 19 August 2011 03:55:13 (Eastern Daylight Time, UTC-04:00)
cartier rond louis watches breitling replica watches breitling meters cartier replica replica cartier cartier tank watches fake omega watches replica omega watches busy chronomat evolution rolex watches replica rolex watches for sale jaeger lecoultre replica tag heuer watches for sale replica tag heuer watches for sale tradi replica watch replica tissot watches.
Tuesday, 27 September 2011 21:43:06 (Eastern Daylight Time, UTC-04:00)
cartier 21 must de watches breitling breitling replica gutter cartier replica watches cartier cartier watches replica omega replica omega Yin chopard miglia watches rolex replica fake rolex milgauss watches watches tag heuer tag heuer watches anastasia fake watches tudor watches.
Tuesday, 15 November 2011 02:53:41 (Eastern Standard Time, UTC-05:00)
It can miraculously unity Ge2011q15, chav, two tribes often believe with UGGS Clearance only almost no.Quite great, could be wearable and heat, but for just about any certain age on what he UGG Boots Clearance sheepskin man, I'm frightened I does one response.Who is the center of the father of anwar UGGS On Clearance? Kate Moss and Eva Lange li and placement than UGG Boots On Clearance the tremendous variety of precious sheepskin boots detachment from your shelves of horrible naked.
Wednesday, 04 January 2012 21:15:46 (Eastern Standard Time, UTC-05:00)
fake watches replica watches for sale rolex watches replica rolex omega bond replica omega omega seamaster watches.
Thursday, 23 February 2012 03:10:49 (Eastern Standard Time, UTC-05:00)
watch brands watches replica silver watches cartier replica cartier screw bracelet, replica breitling breitling watches.
Thursday, 23 February 2012 19:44:17 (Eastern Standard Time, UTC-05:00)
fake watches watches replica mens watch replica tag heuer monaco tag heuer, fake breitling breitling colt.
Thursday, 23 February 2012 21:20:57 (Eastern Standard Time, UTC-05:00)
Wedding dresses bridal gowns Gucci Fleece Mini black dress Ed Hardy Gowns Fashion games BCBG Vests Clothing evening Ed Hardy Casual Dress unique Christian Audigier Pantsuits 3 piece suit.
Friday, 24 February 2012 03:20:03 (Eastern Standard Time, UTC-05:00)
Fashion designer Ed Hardy Casual Clothes Free dresses Gucci Skirts Fashion show Prom Dress La vintage Karen Millen Casual Clothes Fashion week Herve Leger Outerwear Wear shop.
Saturday, 25 February 2012 02:52:49 (Eastern Standard Time, UTC-05:00)
Tuesday, 28 February 2012 21:56:09 (Eastern Standard Time, UTC-05:00)
watches review replica watches nixon watches replica breitling imitation breitling, replica cartier watches cartier eyeglasses.
Monday, 05 March 2012 01:50:25 (Eastern Standard Time, UTC-05:00)
watches replica fake watches watches replica tag heuer watches heuer, parmigiani replica replica parmigiani.
Monday, 05 March 2012 02:46:59 (Eastern Standard Time, UTC-05:00)
oil painting galleries Surrealism oil paintings famous oil painting Still Life oil paintings landscape oil paintings oil paintings reproductions art oil painting Dancers oil paintings oil painting for beginners.
Tuesday, 06 March 2012 00:09:55 (Eastern Standard Time, UTC-05:00)
custom tattoo machines Tattoo Machines digital tattoo power supply Tattoo Case & Box tattoo machine Damascus steel tattoo machines buy tattoo machine.
Wednesday, 07 March 2012 02:15:59 (Eastern Standard Time, UTC-05:00)
air jordan spizike "he is trying to blackmail Jordan Spizike Sale money" Wei Tong security company cheap jordan spizikes buy jordan 23 manager Zhang said: "I think he jordans for sale just wants. air jordans 6 rings for sale
Friday, 09 March 2012 21:27:46 (Eastern Standard Time, UTC-05:00)
Tuesday, 27 March 2012 03:27:17 (Eastern Standard Time, UTC-05:00)
d to purchase any jordan 11 for sale keyword to promote jordan retro 11 advertising, because the Media jordan 11 retro Ads are jordan xi charged a retro jordan 11 flat jordan retro xi rate of implementation. When jordan 11 for sale Google detects the advertising associated with search key...
Tuesday, 27 March 2012 03:28:06 (Eastern Standard Time, UTC-05:00)
ds, they will jordan shoes 11 in the buy jordan 11 search box below the jordan 11 sale search <a
Thursday, 03 May 2012 20:49:28 (Eastern Daylight Time, UTC-04:00)
beats by dre cord beats by dre dre beats by dre customize where to buy beats by dr dre beats laptop by dre beats by dre studio studio beats by dre review monster beats by monster beats by dr dre headphone beats by dre power beats monster power beats by dr dre monster beats wireless headphones wireless beats by dre
Comments are closed.