entity-framework-ctp5

Adding index to a table

旧城冷巷雨未停 提交于 2019-11-26 16:45:30
问题 I have a table Person : id, name I often have queries like: select * from Person where name Like "%abc%". I have 2 questions: How do I implement this query using code-first 5 (CTP5) How do I add an index on the name column to make data retrieval faster based on name like in the query? 回答1: Like operator can be performed with Contains function: var query = from p in context.Persons where p.Name.Contains("abc") select p; Index must be added by SQL - there is no special construction in EF to

Entity Framework Code First: How can I create a One-to-Many AND a One-to-One relationship between two tables?

こ雲淡風輕ζ 提交于 2019-11-26 11:09:49
问题 Here is my Model: public class Customer { public int ID { get; set; } public int MailingAddressID { get; set; } public virtual Address MailingAddress { get; set; } public virtual ICollection<Address> Addresses { get; set; } } public class Address { public int ID { get; set; } public int CustomerID { get; set; } public virtual Customer Customer { get; set; } } A customer can have any number of addresses, however only one of those addresses can be a mailing address. I can get the One to One

How to use DbContext.Database.SqlQuery<TElement>(sql, params) with stored procedure? EF Code First CTP5

假如想象 提交于 2019-11-26 00:23:31
问题 I have a stored procedure that has three parameters and I\'ve been trying to use the following to return the results: context.Database.SqlQuery<myEntityType>(\"mySpName\", param1, param2, param3); At first I tried using SqlParameter objects as the params but this didn\'t work and threw a SqlException with the following message: Procedure or function \'mySpName\' expects parameter \'@param1\', which was not supplied. So my question is how you can use this method with a stored procedure that