Hi
Is Entity Framework worth moving to for a new small app? About 10 tables and a WinForms app.
ie the alternative being DataTables/DataRows or Linq-to-SQL
I have saved a picture in sql server and now i can not to retrieve image and set it's in picturebox with linq.
why byte[] x become null?
private void dataGridViewUser_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = dataGridViewUser.CurrentRow;
byte[] x=(byte[])row.Cells["Image"].Value;
MemoryStream ms1 = new MemoryStream(x);
picuser.Image = Bitmap.FromStream(ms1);
}
Is it somehow possible to use the 'With' keyword on an existing object?
I would like to do the following using LINQ to objects and can't seem to find a way:
From m as Product in Me _
Select m With {.Match = m.Name.IndexOf(query)} _
Where m.Name.IndexOf(query) > 0
I'm having problems when using linq on a datatable.asenumerable().
This throws InvalidCastException.
DateTime date=r.Field<DateTime>("date");
This works fine.
DateTime date = DateTime.Parse(r.Field<string>("date"));
What am I missing?
Regards Sven
if i have this code today to find out a sum total using LINQ:
return (MyArray.Sum(r => r.Trips);
and i want to only include itms where r.CanDrive == true.
can you add a condition into a single linke lambda expression? how would you do this
Hello.
I have a short question. Im my current project I'm using LINQ-to-SQl. That is the best way to determine if table has record with specific ID?
Thanks in advance.
Does any one know of an example on how to store an image in a SQL Server CE database?
What data type should the column be? (I am guessing binary.)
I use Linq-To-Datasets. Is it possible using that to put the image into the database and pull it out again later?
Thanks for any advice.
Consider I have a DataContext db, and there is an Entity class User. So when System.Data.Linq.Table<User> table = db.GetTable<User>(); is called for the first time, does it pull the data from the database immediately, does it use deferred execution, or were the data already loaded from database when db was initialized?
I want to query a xml file.
I read this http://weblogs.asp.net/scottgu/archive/2007/08/07/using-linq-to-xml-and-how-to-build-a-custom-rss-feed-reader-with-it.aspx ,
But in my case i don't know the names of elements and attributes of the file.
So i could i do ?
Thanks
Using InsertOnSubmit seems to have some memory overhead.
I have a System.Data.Linq.Table<User> table. When I do table.InsertOnSubmit(user) and then int count = table.Count(), the memory usage of my application increases by roughly the size of the User table, but the count is the number of items before user was inserted. So I'm guess an enumeration after InsertOnSubmit will create a copy of the table. Is that true?
These web articles uses separate Save() and Update() methods in the repository pattern.
I am using repository pattern.
How can I write a SaveOrUpdate() method in Entity Framework with the help of ObjectContext and in Linq-To-SQL with the help of DataContext?
That is, how can I write a single method that shall do both save and update job?
Going thru one of my favourite authors question What’s the hardest or most misunderstood aspect of LINQ? I am basically looking for the answer of the question:
How the C# compiler treats query expressions
Thanks
I have ~10,000 records would like to keep in a collection in memory and execute LINQ queries against it. This collection should be available for all the users in the application domain and can access concurrently. I’m looking for a .NET collection that supports multithreading can query asynchronously and efficiently without any threading issues. Any suggestions on deciding a collection for this?
This lambda does not compile, but I do not understand why.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using LinqKit;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var barModel = new BarModel();
string id = "some";
Console.WriteLine(barModel.subFor(id).ToString());
// output: m => (True AndAlso (m.key == value(ConsoleApplication2.Bar`1+<>c__DisplayClass0[ConsoleApplication2.Model]).id))
Console.ReadKey();
var subworkitems = barModel.list.Where(barModel.subFor(id).Compile());
// Exception {"variable 'm' of type 'ConsoleApplication2.Model' referenced from scope '', but it is not defined"}
Console.WriteLine(subworkitems.ToString());
Console.ReadKey();
}
}
class Bar<TModel>
{
public Bar(Expression<Func<TModel, string>> foreignKeyExpression)
{
_foreignKeyExpression = foreignKeyExpression;
}
private Expression<Func<TModel, string>> _foreignKeyExpression { get; set; }
public Expression<Func<TModel, bool>> subFor(string id)
{
var ex = forTargetId(id);
return ex;
}
public Expression<Func<TModel, bool>> forTargetId(String id)
{
var fc = _foreignKeyExpression;
Expression<Func<TModel, bool>> predicate = m => true;
var result = predicate.And(m => fc.Invoke(m) == id).Expand();
return result;
}
}
class Model
{
public string key;
public string value;
}
class BarModel : Bar<Model>
{
public List<Model> list;
public BarModel() : base(m => m.key)
{
list = new List<Model>();
}
}
}
I've got a ILookup< string, List<CustomObject> > from some linq I've done.
I'd like to now iterate over the results:
foreach(IGrouping<string, List<CustomObject>> groupItem in lookupTable)
{
groupItem.Key; //You can access the key, but not the list of CustomObject
}
I know I must be misrepresenting a IGrouping as a KeyValuePair, but now I'm not sure how to access it properly.
If I try:
Groups = students.Remove(f => f.StudentID.Equals(studentID));
I get an error on this line: f => f.StudentID.Equals(studentID)
I am having difficulty from my previous posts here linq deleted users still associated with groups and here Delete method in WCF
So I thought maybe I could delete the students contained within groups but I get an error Cannot convert lamda expression to type Student because it is not a delegate type.
I'm trying to cast an IEnumerable of an inherited type to IEnumerable of base class.
Have tried following:
var test = resultFromDb.Cast<BookedResource>();
return test.ToList();
But getting error:
You cannot convert these types. Linq to Entities only supports conversion primitive EDM-types.
The classes involved look like this:
public partial class HistoryBookedResource : BookedResource
{
}
public partial class HistoryBookedResource
{
public int ResourceId { get; set; }
public string DateFrom { get; set; }
public string TimeFrom { get; set; }
public string TimeTo { get; set; }
}
public partial class BookedResource
{
public int ResourceId { get; set; }
public string DateFrom { get; set; }
public string TimeFrom { get; set; }
public string TimeTo { get; set; }
}
[MetadataType(typeof(BookedResourceMetaData))]
public partial class BookedResource
{
}
public class BookedResourceMetaData
{
[Required(ErrorMessage = "Resource id is Required")]
[Range(0, int.MaxValue, ErrorMessage = "Resource id is must be an number")]
public object ResourceId { get; set; }
[Required(ErrorMessage = "Date is Required")]
public object DateFrom { get; set; }
[Required(ErrorMessage = "Time From is Required")]
public object TimeFrom { get; set; }
[Required(ErrorMessage = "Time to is Required")]
public object TimeTo { get; set; }
}
The problem I'm trying to solve is to get records from table HistoryBookedResource and have the result in an IEnumerable<BookedResource> using Entity Framework and LINQ.
UPDATE:
When using the following the cast seams to work but when trying to loop with a foreach the data is lost.
resultFromDb.ToList() as IEnumerable<BookedResource>;
UPDATE 2:
Im using entity frameworks generated model, model (edmx) is created from database, edmx include classes that reprecent the database tables.
In database i have a history table for old BookedResource and it can happen that the user want to look at these and to get the old data from the database entity framework uses classes with the same name as the tables to receive data from db. So i receive the data from table HistoryBookedResource in HistoryBookedResource class.
Because entity framework generate the partial classes with the properties i dont know if i can make them virtual and override.
Any suggestions will be greatly appreciated.
Hi,
Suppose 2 classes, Person and Pet. Each person has a collection of 1 or more pets.
How do i group the Person in to a collection where they share the same pets.
Example:
Person 1: Cat, Dog, Spider
Person 2: Cat, Spider, Snake
Person 3: Dog
Person 4: Spider, Cat, Dog
Person 5: Dog
What i want as a result is this:
Group 1: Person 1, Person 4
Group 2: Person 3, Person 5
Group 3: Person 2
How do i achieve this using LINQ?
I created a Windows Forms Application to which I added a DataGridView and LINQ to SQL Classes from one of my databases. I can successfully bind one of my database's tables to my DataGridView:
var dataSource = from c in _db.NetworkedEquipments
select c;
dataGridView1.DataSource = dataSource;
However, the foreign keys get duplicated, that is, the columns appear twice. How can I prevent this?
I'm using LinqToSql like this with a CheckBoxList in ASP.NET:
var teachers = from x in dc.teachers select x;
cbl.DataSource = teachers;
cbl.DataTextField = "name";
cbl.DataValueField = "teacherID";
cbl.DataBind();
I want to display both "firstname" and "name" in the DataTextField however.
I found this solution but I'm using LINQ:
http://stackoverflow.com/questions/839223/concatenate-two-fields-in-a-dropdown
How do I do this?
I have two long type columns that I want to concat during sql query. Using Linq to Entities making it impossible, because it only supports String.Concat(string, string).
I'd like to know how can I implement this function myself and add it to the L2E framework.
In my web application, I have a dynamic query that returns huge data to datatable, and this query is often recalled with different parameters. So database is exhausted.
I want to get all record with no parameters to an object, and perform queries (may be with linq) on this object. So database will not be exthausted.
Which objects can be used instead of datatable?
Hello!
I have IEnumerable - that i recieved(converted) from dattabase.
i need to select from this collection only unique strings.
i suppose that i need to use linq group by string...
please help.
I have a requirement to have a multiline textbox that accepts any text from any language and stores this into the database for later use.
I am using Linq with ASP .NET 3.5 with a SQL Server 2005 database.
Any/all information you can provide me with is much appreciated :D
Hi,
Can we use foreach loop for Iqueryable object?
I'd like to do something as follow:
query = Iqueryable<Myclass> = objDataContext.Myclass; // objDataContext is an object of LINQ datacontext class
int[] arr1 = new int[] { 3, 4, 5 };
foreach (int i in arr1)
{
query = query.Where(q => (q.f_id1 == i || q.f_id2 == i || q.f_id3 == i));
}
It gives me wrong output as each time value if i is changed.