Вопрос

I am trying to delete a row from an entity named xyz in CRM using the following code in LINQPAD

    var d = from z in xyz
where z.exch_ZipCode == "60069" 
&& z.exch_zipcodeId.Value== new Guid("c6e88a07-b4a2-e211-b8d2-bc305befb465")
select new
{
zipId = z.exch_zipcodeId.Value,
zip = z.exch_ZipCode,
};
d.AsEnumerable().ToList().ForEach(row=>row.Delete());

I have added System.Data.DataSetExtensions.dll but I get the following error

'AnonymousType#1' does not contain a definition for 'Delete' and no extension method 'Delete' accepting a first argument of type 'AnonymousType#1' could be found (press F4 to add a using directive or assembly reference)

Это было полезно?

Решение

If this is LinqToSql then to delete rows you use DeleteOnSubmit or DeleteAllOnSubmit.

For example, if you want to delete all rows in xyz matching your criteria, you can do something like :

var query = (from z in xyz
    where z.exch_ZipCode == "60069" 
       && z.exch_zipcodeId.Value== new Guid("c6e88a07-b4a2-e211-b8d2-bc305befb465")
    select z);

xyz.DeleteAllOnSumit(query);
SubmitChanges();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top